-
Notifications
You must be signed in to change notification settings - Fork 9
ING-1329: Add testing for client cert auth #315
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| name: Run Client Cert Auth Tests | ||
| permissions: | ||
| contents: read | ||
| packages: read | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - v* | ||
| branches: | ||
| - master | ||
| pull_request: | ||
| jobs: | ||
| test: | ||
| name: Test | ||
| strategy: | ||
| matrix: | ||
| server: | ||
| - 8.1.0-1203 | ||
| - 8.0.0 | ||
| - 7.6.8 | ||
| - 7.2.8 | ||
|
|
||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| submodules: recursive | ||
| - name: Install cbdinocluster | ||
| uses: ./.github/actions/install-cbdinocluster | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Start couchbase cluster | ||
| id: start-cluster | ||
| uses: ./.github/actions/start-couchbase-cluster | ||
| - uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: 1.24 | ||
| - uses: arduino/setup-protoc@v3 | ||
| with: | ||
| version: 31.1 | ||
| repo-token: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Install Tools | ||
| run: | | ||
| go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.36 | ||
| go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.5 | ||
| go install github.com/matryer/moq@v0.5 | ||
| - name: Install Dependencies | ||
| run: go get ./... | ||
| - name: Generate Files | ||
| run: | | ||
| go generate ./... | ||
| - name: Run Test | ||
| env: | ||
| SGTEST_CBCONNSTR: ${{ steps.start-cluster.outputs.node-ip }} | ||
| SGTEST_DINOID: ${{ steps.start-cluster.outputs.dino-id }} | ||
| run: go test ./gateway/test -run TestGatewayOps -v -testify.m TestClientCertAuth | ||
|
|
||
| - name: Collect couchbase logs | ||
| timeout-minutes: 10 | ||
| if: failure() | ||
| run: | | ||
| mkdir -p ./client-cert-auth-logs | ||
| cbdinocluster -v collect-logs ${{ steps.start-cluster.outputs.dino-id }} ./client-cert-auth-logs | ||
| - name: Upload couchbase logs | ||
| if: failure() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: cbcollect-logs-${{ matrix.server }} | ||
| path: ./client-cert-auth-logs/* | ||
| retention-days: 5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| package test | ||
|
|
||
| import ( | ||
| "context" | ||
| "crypto/tls" | ||
| "time" | ||
|
|
||
| "github.com/couchbase/goprotostellar/genproto/kv_v1" | ||
| "github.com/couchbase/stellar-gateway/testutils" | ||
| "github.com/stretchr/testify/assert" | ||
| "google.golang.org/grpc" | ||
| "google.golang.org/grpc/codes" | ||
| "google.golang.org/grpc/credentials" | ||
| ) | ||
|
|
||
| func (s *GatewayOpsTestSuite) TestClientCertAuth() { | ||
| testutils.SkipIfNoDinoCluster(s.T()) | ||
|
|
||
| s.Run("KvService", s.KvService) | ||
| } | ||
|
|
||
| func (s *GatewayOpsTestSuite) KvService() { | ||
| dino := testutils.StartDinoTesting(s.T(), false) | ||
| username := "kvUser" | ||
| conn := s.newClientCertConn(dino, username) | ||
| kvClient := kv_v1.NewKvServiceClient(conn) | ||
| getFn := func() (*kv_v1.GetResponse, error) { | ||
| return kvClient.Get(context.Background(), &kv_v1.GetRequest{ | ||
| BucketName: s.bucketName, | ||
| ScopeName: s.scopeName, | ||
| CollectionName: s.collectionName, | ||
| Key: s.testDocId(), | ||
| }) | ||
| } | ||
|
|
||
| s.Run("UserMissing", func() { | ||
| _, err := getFn() | ||
| assertRpcStatus(s.T(), err, codes.PermissionDenied) | ||
| assert.Contains(s.T(), err.Error(), "Your certificate is invalid") | ||
| }) | ||
|
|
||
| dino.AddUnprivilegedUser(username) | ||
| time.Sleep(time.Second * 5) | ||
| s.T().Cleanup(func() { | ||
| dino.RemoveUser(username) | ||
| }) | ||
|
|
||
| s.Run("NoUserPermissions", func() { | ||
| _, err := getFn() | ||
| assertRpcStatus(s.T(), err, codes.PermissionDenied) | ||
| assert.Contains(s.T(), err.Error(), "No permissions to read documents") | ||
| }) | ||
|
|
||
| dino.AddReadOnlyUser(username) | ||
| time.Sleep(time.Second * 5) | ||
|
chvck marked this conversation as resolved.
|
||
|
|
||
| s.Run("ReadSuccess", func() { | ||
| resp, err := getFn() | ||
| requireRpcSuccess(s.T(), resp, err) | ||
| }) | ||
|
|
||
| s.Run("NoWritePermission", func() { | ||
| docId := s.randomDocId() | ||
| _, err := kvClient.Upsert(context.Background(), &kv_v1.UpsertRequest{ | ||
| BucketName: s.bucketName, | ||
| ScopeName: s.scopeName, | ||
| CollectionName: s.collectionName, | ||
| Key: docId, | ||
| Content: &kv_v1.UpsertRequest_ContentUncompressed{ | ||
| ContentUncompressed: TEST_CONTENT, | ||
| }, | ||
| ContentFlags: TEST_CONTENT_FLAGS, | ||
| }) | ||
| assertRpcStatus(s.T(), err, codes.PermissionDenied) | ||
| assert.Contains(s.T(), err.Error(), "No permissions to write documents") | ||
| }) | ||
|
|
||
| dino.AddWriteUser(username) | ||
| time.Sleep(time.Second * 5) | ||
|
|
||
| s.Run("WriteSuccess", func() { | ||
| docId := s.randomDocId() | ||
| resp, err := kvClient.Upsert(context.Background(), &kv_v1.UpsertRequest{ | ||
| BucketName: s.bucketName, | ||
| ScopeName: s.scopeName, | ||
| CollectionName: s.collectionName, | ||
| Key: docId, | ||
| Content: &kv_v1.UpsertRequest_ContentUncompressed{ | ||
| ContentUncompressed: TEST_CONTENT, | ||
| }, | ||
| ContentFlags: TEST_CONTENT_FLAGS, | ||
| }) | ||
| requireRpcSuccess(s.T(), resp, err) | ||
| assertValidCas(s.T(), resp.Cas) | ||
| assertValidMutationToken(s.T(), resp.MutationToken, s.bucketName) | ||
| }) | ||
| } | ||
|
|
||
| func (s *GatewayOpsTestSuite) newClientCertConn(dino *testutils.DinoController, username string) *grpc.ClientConn { | ||
| res := dino.GetClientCert(username) | ||
|
|
||
| cert, err := tls.X509KeyPair([]byte(res), []byte(res)) | ||
| assert.NoError(s.T(), err) | ||
|
|
||
| conn, err := grpc.NewClient(s.gwConnAddr, | ||
| grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{ | ||
| RootCAs: s.clientCaCertPool, | ||
| Certificates: []tls.Certificate{cert}, | ||
| }))) | ||
| if err != nil { | ||
| s.T().Fatalf("failed to connect to test gateway: %s", err) | ||
| } | ||
|
|
||
| return conn | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.