diff --git a/plugin/service/host/plugin.go b/plugin/service/host/plugin.go index 9dbe72d..1421bf0 100644 --- a/plugin/service/host/plugin.go +++ b/plugin/service/host/plugin.go @@ -87,6 +87,10 @@ func (p *HostPlugin) OnCreateCatalog(ctx context.Context, req *pb.OnCreateCatalo credential.IAMServiceAccountKeysDeletePermission, } + if !credState.CredentialsConfig.IsRotatable() && !catalogAttributes.DisableCredentialRotation { + return nil, status.Error(codes.InvalidArgument, "cannot rotate credentials for non-rotatable credentials") + } + if credState.CredentialsConfig.IsRotatable() && !catalogAttributes.DisableCredentialRotation { if err := credState.RotateCreds(ctx, permissions, p.testGCPClientOpts...); err != nil { return nil, err diff --git a/plugin/service/host/plugin_test.go b/plugin/service/host/plugin_test.go index 33ed630..629451d 100644 --- a/plugin/service/host/plugin_test.go +++ b/plugin/service/host/plugin_test.go @@ -878,6 +878,53 @@ func TestCreateCatalog(t *testing.T) { }, }, }, + { + name: "create with application default credentials and credential rotation disabled", + req: &pb.OnCreateCatalogRequest{ + Catalog: &hostcatalogs.HostCatalog{ + Attrs: &hostcatalogs.HostCatalog_Attributes{ + Attributes: &structpb.Struct{ + Fields: map[string]*structpb.Value{ + cred.ConstProjectId: structpb.NewStringValue("test-project"), + cred.ConstZone: structpb.NewStringValue("us-central1-a"), + cred.ConstDisableCredentialRotation: structpb.NewBoolValue(true), + }, + }, + }, + }, + }, + catalogOpts: []gcpCatalogPersistedStateOption{ + withTestInstancesAPIFunc(newTestMockInstances(ctx, + nil, + testMockInstancesWithListInstancesOutput(&computepb.InstanceList{}), + testMockInstancesWithListInstancesError(nil), + )), + }, + expectedRsp: &pb.OnCreateCatalogResponse{ + Persisted: &pb.HostCatalogPersisted{ + Secrets: &structpb.Struct{ + Fields: map[string]*structpb.Value{}, + }, + }, + }, + }, + { + name: "create with application default credentials and credential rotation enabled", + req: &pb.OnCreateCatalogRequest{ + Catalog: &hostcatalogs.HostCatalog{ + Attrs: &hostcatalogs.HostCatalog_Attributes{ + Attributes: &structpb.Struct{ + Fields: map[string]*structpb.Value{ + cred.ConstProjectId: structpb.NewStringValue("test-project"), + cred.ConstZone: structpb.NewStringValue("us-central1-a"), + cred.ConstDisableCredentialRotation: structpb.NewBoolValue(false), + }, + }, + }, + }, + }, + expectedErr: "cannot rotate credentials for non-rotatable credentials", + }, } for _, tc := range cases {