Skip to content

[public-api] Caddy serves gRPC port instead of http #9482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2022

Conversation

easyCZ
Copy link
Member

@easyCZ easyCZ commented Apr 22, 2022

Description

For now, we've been serving HTTP to easily show the server runs. But we actually need to serve the gRPC port for the API.

gRPC requires that we know the cert of the server, such that we can establish a TLS connection.

Related Issue(s)

How to test

The easy way:

  1. Open workspace from [public-api] Simple CLI tool to interact with Public API #9588
  2. cd components/public-api-server/cmd
  3. go run main.go workspace get --address apimp-papi-caddy-grpc.preview.gitpod-dev.com:443
  4. Observe it connects and returns Unimplemented - this is the expected response!

The hard way:

  • There is no client implemented at this stage yet.
  • Fetch the public certificate we use for *.<domain> in preview envs with
kubectl get secret proxy-config-certificates -o yaml | yq '.data.["tls.crt"]' | base64 -d > tls.crt
  • Extend the components/public-api-server/integration_test.go with, update pemServerCA path to where you wrote the tls.crt
func loadTLSCredentials() (credentials.TransportCredentials, error) {
	// Load certificate of the CA who signed server's certificate
	// TO TEST: update this path to where you downloaded the cert
	pemServerCA, err := ioutil.ReadFile("/workspace/gitpod/tls.crt")
	if err != nil {
		return nil, err
	}

	certPool := x509.NewCertPool()
	if !certPool.AppendCertsFromPEM(pemServerCA) {
		return nil, fmt.Errorf("failed to add server CA's certificate")
	}

	// Create the credentials and return it
	config := &tls.Config{
		RootCAs: certPool,
		CipherSuites: []uint16{
			tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
			tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
			tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
			tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
			tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
			tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
		},
		CurvePreferences: []tls.CurveID{tls.X25519, tls.CurveP256},
		MinVersion:       tls.VersionTLS12,
		MaxVersion:       tls.VersionTLS12,
		NextProtos:       []string{"h2"},
	}

	return credentials.NewTLS(config), nil
}

func TestPublicAPIServer_v1(t *testing.T) {
	ctx := context.Background()
	tlsCredentials, err := loadTLSCredentials()
	require.NoError(t, err)

	addr := "api.mp-papi-caddy-grpc.preview.gitpod-dev.com:443"
	var opts []grpc.DialOption

	opts = append(opts, grpc.WithTransportCredentials(tlsCredentials))

	conn, err := grpc.Dial(addr, opts...)
	require.NoError(t, err)

	workspaceClient := v1.NewWorkspacesServiceClient(conn)

	_, err = workspaceClient.GetWorkspace(ctx, &v1.GetWorkspaceRequest{})
	requireErrorStatusCode(t, codes.Unimplemented, err)
}

Release Notes

NONE

Documentation

NONE

/werft with-vm

@easyCZ
Copy link
Member Author

easyCZ commented Apr 25, 2022

/werft run with-vm=true

👍 started the job as gitpod-build-mp-papi-caddy-grpc.22
(with .werft/ from main)

@easyCZ
Copy link
Member Author

easyCZ commented Apr 25, 2022

/werft run with-vm=true with-clean-slate-deployment=true

👍 started the job as gitpod-build-mp-papi-caddy-grpc.27
(with .werft/ from main)

@easyCZ easyCZ force-pushed the mp/papi-caddy-grpc branch from b8b4f3c to 40535a4 Compare April 25, 2022 19:44
@roboquat roboquat added size/L and removed size/M labels Apr 25, 2022
@easyCZ
Copy link
Member Author

easyCZ commented Apr 25, 2022

/werft run

👍 started the job as gitpod-build-mp-papi-caddy-grpc.31
(with .werft/ from main)

@easyCZ easyCZ force-pushed the mp/papi-caddy-grpc branch 2 times, most recently from 05b6e25 to ae270b8 Compare April 27, 2022 06:54
@roboquat roboquat added size/M and removed size/L labels Apr 27, 2022
@easyCZ easyCZ force-pushed the mp/papi-caddy-grpc branch from bfecc0a to 2306861 Compare April 27, 2022 06:57
@roboquat roboquat added size/S and removed size/M labels Apr 27, 2022
@easyCZ
Copy link
Member Author

easyCZ commented Apr 27, 2022

/werft run with-vm=true with-clean-slate-deployment=true

👍 started the job as gitpod-build-mp-papi-caddy-grpc.52
(with .werft/ from main)

@easyCZ easyCZ force-pushed the mp/papi-caddy-grpc branch from 2306861 to 42dfb99 Compare April 27, 2022 08:03
@easyCZ easyCZ marked this pull request as ready for review April 27, 2022 08:03
@easyCZ easyCZ requested a review from a team April 27, 2022 08:03
@github-actions github-actions bot added the team: webapp Issue belongs to the WebApp team label Apr 27, 2022
@easyCZ
Copy link
Member Author

easyCZ commented Apr 27, 2022

If you want to have a laugh, it took about a week to figure out the right 10 lines (or so) in this PR..

Copy link
Member

@AlexTugarev AlexTugarev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@roboquat roboquat merged commit 997c604 into main Apr 28, 2022
@roboquat roboquat deleted the mp/papi-caddy-grpc branch April 28, 2022 07:15
@roboquat roboquat added deployed: webapp Meta team change is running in production deployed Change is completely running in production labels Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployed: webapp Meta team change is running in production deployed Change is completely running in production release-note-none size/S team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants