diff --git a/app/cli/cmd/organization_apitoken_list.go b/app/cli/cmd/organization_apitoken_list.go index 18d1d0b8e..95a0ac582 100644 --- a/app/cli/cmd/organization_apitoken_list.go +++ b/app/cli/cmd/organization_apitoken_list.go @@ -36,6 +36,7 @@ func newAPITokenListCmd() *cobra.Command { var availableScopes = []string{ "project", "global", + "product", } var availableStatusFilters = []string{ diff --git a/app/cli/documentation/cli-reference.md b/app/cli/documentation/cli-reference.md index 01ec5e823..756245fce 100644 --- a/app/cli/documentation/cli-reference.md +++ b/app/cli/documentation/cli-reference.md @@ -2112,7 +2112,7 @@ Options ``` -h, --help[=true|false] help for list -p, --project string filter by project name --s, --scope string filter by scope, available scopes: [project global] +-s, --scope string filter by scope, available scopes: [project global product] --status string filter by token status, available values: [active revoked all] ``` diff --git a/app/cli/pkg/action/apitoken_list.go b/app/cli/pkg/action/apitoken_list.go index 93500ca3c..0b82437fb 100644 --- a/app/cli/pkg/action/apitoken_list.go +++ b/app/cli/pkg/action/apitoken_list.go @@ -61,6 +61,8 @@ func mapScope(scope string) pb.APITokenServiceListRequest_Scope { return pb.APITokenServiceListRequest_SCOPE_PROJECT case "global": return pb.APITokenServiceListRequest_SCOPE_GLOBAL + case "product": + return pb.APITokenServiceListRequest_SCOPE_PRODUCT default: return pb.APITokenServiceListRequest_SCOPE_UNSPECIFIED } diff --git a/app/controlplane/api/controlplane/v1/api_token.pb.go b/app/controlplane/api/controlplane/v1/api_token.pb.go index 9d5d62026..9b4556c16 100644 --- a/app/controlplane/api/controlplane/v1/api_token.pb.go +++ b/app/controlplane/api/controlplane/v1/api_token.pb.go @@ -44,6 +44,8 @@ const ( APITokenServiceListRequest_SCOPE_UNSPECIFIED APITokenServiceListRequest_Scope = 0 APITokenServiceListRequest_SCOPE_PROJECT APITokenServiceListRequest_Scope = 1 APITokenServiceListRequest_SCOPE_GLOBAL APITokenServiceListRequest_Scope = 2 + // Tokens confined to the projects of a product. + APITokenServiceListRequest_SCOPE_PRODUCT APITokenServiceListRequest_Scope = 3 ) // Enum value maps for APITokenServiceListRequest_Scope. @@ -52,11 +54,13 @@ var ( 0: "SCOPE_UNSPECIFIED", 1: "SCOPE_PROJECT", 2: "SCOPE_GLOBAL", + 3: "SCOPE_PRODUCT", } APITokenServiceListRequest_Scope_value = map[string]int32{ "SCOPE_UNSPECIFIED": 0, "SCOPE_PROJECT": 1, "SCOPE_GLOBAL": 2, + "SCOPE_PRODUCT": 3, } ) @@ -526,16 +530,17 @@ const file_controlplane_v1_api_token_proto_rawDesc = "" + "\x03jwt\x18\x02 \x01(\tR\x03jwt\"8\n" + "\x1cAPITokenServiceRevokeRequest\x12\x18\n" + "\x02id\x18\x01 \x01(\tB\b\xbaH\x05r\x03\xb0\x01\x01R\x02id\"\x1f\n" + - "\x1dAPITokenServiceRevokeResponse\"\xd0\x03\n" + + "\x1dAPITokenServiceRevokeResponse\"\xe3\x03\n" + "\x1aAPITokenServiceListRequest\x12+\n" + "\x0finclude_revoked\x18\x01 \x01(\bB\x02\x18\x01R\x0eincludeRevoked\x12<\n" + "\aproject\x18\x04 \x01(\v2\".controlplane.v1.IdentityReferenceR\aproject\x12G\n" + "\x05scope\x18\x02 \x01(\x0e21.controlplane.v1.APITokenServiceListRequest.ScopeR\x05scope\x12]\n" + - "\rstatus_filter\x18\x05 \x01(\x0e28.controlplane.v1.APITokenServiceListRequest.StatusFilterR\fstatusFilter\"C\n" + + "\rstatus_filter\x18\x05 \x01(\x0e28.controlplane.v1.APITokenServiceListRequest.StatusFilterR\fstatusFilter\"V\n" + "\x05Scope\x12\x15\n" + "\x11SCOPE_UNSPECIFIED\x10\x00\x12\x11\n" + "\rSCOPE_PROJECT\x10\x01\x12\x10\n" + - "\fSCOPE_GLOBAL\x10\x02\"Z\n" + + "\fSCOPE_GLOBAL\x10\x02\x12\x11\n" + + "\rSCOPE_PRODUCT\x10\x03\"Z\n" + "\fStatusFilter\x12\x18\n" + "\x14STATUS_FILTER_ACTIVE\x10\x00\x12\x19\n" + "\x15STATUS_FILTER_REVOKED\x10\x01\x12\x15\n" + diff --git a/app/controlplane/api/controlplane/v1/api_token.proto b/app/controlplane/api/controlplane/v1/api_token.proto index b73d39240..8d977dacf 100644 --- a/app/controlplane/api/controlplane/v1/api_token.proto +++ b/app/controlplane/api/controlplane/v1/api_token.proto @@ -65,6 +65,8 @@ message APITokenServiceListRequest { SCOPE_UNSPECIFIED = 0; SCOPE_PROJECT = 1; SCOPE_GLOBAL = 2; + // Tokens confined to the projects of a product. + SCOPE_PRODUCT = 3; } // filter by the scope of the token diff --git a/app/controlplane/api/gen/frontend/controlplane/v1/api_token.ts b/app/controlplane/api/gen/frontend/controlplane/v1/api_token.ts index 1aab5c571..eeffe0788 100644 --- a/app/controlplane/api/gen/frontend/controlplane/v1/api_token.ts +++ b/app/controlplane/api/gen/frontend/controlplane/v1/api_token.ts @@ -53,6 +53,8 @@ export enum APITokenServiceListRequest_Scope { SCOPE_UNSPECIFIED = 0, SCOPE_PROJECT = 1, SCOPE_GLOBAL = 2, + /** SCOPE_PRODUCT - Tokens confined to the projects of a product. */ + SCOPE_PRODUCT = 3, UNRECOGNIZED = -1, } @@ -67,6 +69,9 @@ export function aPITokenServiceListRequest_ScopeFromJSON(object: any): APITokenS case 2: case "SCOPE_GLOBAL": return APITokenServiceListRequest_Scope.SCOPE_GLOBAL; + case 3: + case "SCOPE_PRODUCT": + return APITokenServiceListRequest_Scope.SCOPE_PRODUCT; case -1: case "UNRECOGNIZED": default: @@ -82,6 +87,8 @@ export function aPITokenServiceListRequest_ScopeToJSON(object: APITokenServiceLi return "SCOPE_PROJECT"; case APITokenServiceListRequest_Scope.SCOPE_GLOBAL: return "SCOPE_GLOBAL"; + case APITokenServiceListRequest_Scope.SCOPE_PRODUCT: + return "SCOPE_PRODUCT"; case APITokenServiceListRequest_Scope.UNRECOGNIZED: default: return "UNRECOGNIZED"; diff --git a/app/controlplane/api/gen/jsonschema/controlplane.v1.APITokenServiceListRequest.jsonschema.json b/app/controlplane/api/gen/jsonschema/controlplane.v1.APITokenServiceListRequest.jsonschema.json index 711340e7e..2703de3a3 100644 --- a/app/controlplane/api/gen/jsonschema/controlplane.v1.APITokenServiceListRequest.jsonschema.json +++ b/app/controlplane/api/gen/jsonschema/controlplane.v1.APITokenServiceListRequest.jsonschema.json @@ -42,7 +42,8 @@ "enum": [ "SCOPE_UNSPECIFIED", "SCOPE_PROJECT", - "SCOPE_GLOBAL" + "SCOPE_GLOBAL", + "SCOPE_PRODUCT" ], "title": "Scope", "type": "string" diff --git a/app/controlplane/api/gen/jsonschema/controlplane.v1.APITokenServiceListRequest.schema.json b/app/controlplane/api/gen/jsonschema/controlplane.v1.APITokenServiceListRequest.schema.json index d4b6d4103..7724a56f9 100644 --- a/app/controlplane/api/gen/jsonschema/controlplane.v1.APITokenServiceListRequest.schema.json +++ b/app/controlplane/api/gen/jsonschema/controlplane.v1.APITokenServiceListRequest.schema.json @@ -42,7 +42,8 @@ "enum": [ "SCOPE_UNSPECIFIED", "SCOPE_PROJECT", - "SCOPE_GLOBAL" + "SCOPE_GLOBAL", + "SCOPE_PRODUCT" ], "title": "Scope", "type": "string" diff --git a/app/controlplane/internal/service/apitoken.go b/app/controlplane/internal/service/apitoken.go index f0857ac03..e152cca92 100644 --- a/app/controlplane/internal/service/apitoken.go +++ b/app/controlplane/internal/service/apitoken.go @@ -134,6 +134,8 @@ func mapTokenScope(scope pb.APITokenServiceListRequest_Scope) authz.ResourceType return authz.ResourceTypeProject case pb.APITokenServiceListRequest_SCOPE_GLOBAL: return authz.ResourceTypeOrganization + case pb.APITokenServiceListRequest_SCOPE_PRODUCT: + return authz.ResourceTypeProduct } return "" diff --git a/app/controlplane/internal/service/apitoken_test.go b/app/controlplane/internal/service/apitoken_test.go index 1478f1043..d602e2ecb 100644 --- a/app/controlplane/internal/service/apitoken_test.go +++ b/app/controlplane/internal/service/apitoken_test.go @@ -76,6 +76,12 @@ func TestAPITokenServiceListForcesProjectScopeForOrgTokens(t *testing.T) { requested: pb.APITokenServiceListRequest_SCOPE_GLOBAL, wantScope: authz.ResourceTypeProject, }, + { + name: "an organization token asking for product tokens is still forced", + caller: &entities.APIToken{ID: uuid.NewString(), Scope: biz.ToPtr(authz.ResourceTypeOrganization), ScopeID: &orgID}, + requested: pb.APITokenServiceListRequest_SCOPE_PRODUCT, + wantScope: authz.ResourceTypeProject, + }, { // Not organization-wide either, and confined to nothing: narrowed to no project. name: "a token recording no scope is narrowed to no project", @@ -110,6 +116,11 @@ func TestAPITokenServiceListForcesProjectScopeForOrgTokens(t *testing.T) { requested: pb.APITokenServiceListRequest_SCOPE_GLOBAL, wantScope: authz.ResourceTypeOrganization, }, + { + name: "a user asking for product tokens gets them", + requested: pb.APITokenServiceListRequest_SCOPE_PRODUCT, + wantScope: authz.ResourceTypeProduct, + }, { name: "a user asking for no scope gets none", wantScope: "", @@ -254,6 +265,7 @@ func TestMapTokenScope(t *testing.T) { {in: pb.APITokenServiceListRequest_SCOPE_UNSPECIFIED, want: ""}, {in: pb.APITokenServiceListRequest_SCOPE_PROJECT, want: authz.ResourceTypeProject}, {in: pb.APITokenServiceListRequest_SCOPE_GLOBAL, want: authz.ResourceTypeOrganization}, + {in: pb.APITokenServiceListRequest_SCOPE_PRODUCT, want: authz.ResourceTypeProduct}, } for _, tc := range testCases {