Skip to content

Commit 8447e09

Browse files
abKiraLempereur-Spacelift
authored andcommitted
Fix OIDC docs to include the entire space ID.
The JWTs issued by Spacelift actually contain the entire space ID, not just the name. This means that the previously documented conditions for AWS and Azure do not match the actual `sub`. For example, following the old example to restrict the role to a particular space by name: ``` "StringLike": { "demo.app.spacelift.io:sub": "space:production:*" } ``` This does not match the actual JWT subject, which looks like this: ``` space:production-01HND497T9JKR76MR3KA2CDJHP:stack:my-stack:run_type:PROPOSED:scope:read ``` I'm not sure if this ID format changed at some point. (Maybe historically space IDs did not have a random suffix?) From what I can see, all spaces have a random ID except the special root space (ID `root`). The docs page for GCP seems to correctly show the full space ID already.
1 parent dcc9b6a commit 8447e09

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

docs/integrations/cloud-providers/oidc/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ The token contains the following standard claims:
6666

6767
- `iss`: The issuer of the token. This is the URL of your Spacelift account, for example `https://demo.app.spacelift.io`, and is unique for each Spacelift account.
6868
- `sub`: The subject of the token, which includes some information about the Spacelift run that generated this token.
69-
- The subject claim is constructed as follows: `space:<space_id>:(stack|module):<stack_id|module_id>:run_type:<run_type>:scope:<read|write>`. For example, `space:legacy:stack:infra:run_type:TRACKED:scope:write`. Individual values are also available as separate [custom claims](#custom-claims).
69+
- The subject claim is constructed as follows: `space:<space_id>:(stack|module):<stack_id|module_id>:run_type:<run_type>:scope:<read|write>`. For example, `space:legacy-01KJMM56VS4W3AL9YZWVCXBX8D:stack:infra:run_type:TRACKED:scope:write`. Individual values are also available as separate [custom claims](#custom-claims).
7070
- `aud`: The audience of the token. This is the hostname of your Spacelift account, for example `demo.app.spacelift.io`, and is unique for each Spacelift account.
7171
- `exp`: The expiration time of the token, in seconds since the Unix epoch. The token is valid for one hour.
7272
- `iat`: The time at which the token was issued, in seconds since the Unix epoch.

docs/integrations/cloud-providers/oidc/aws-oidc.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ If you go to your new role's details page, in the _Trust relationships_ section
5959

6060
![Trust relationship](<../../../assets/screenshots/oidc/aws-iam-trust-relationship.png>)
6161

62-
This trust relationship is very relaxed and will allow any stack or module in the `demo` Spacelift account to assume this role. If you want to be more restrictive, you will want to add more conditions. For example, we can restrict the role to be only assumable by stacks in the `production` space by adding the following condition:
62+
This trust relationship is very relaxed and will allow any stack or module in the `demo` Spacelift account to assume this role. If you want to be more restrictive, you will want to add more conditions. For example, we can restrict the role to be only assumable by stacks in the `production` space (with space ID `production-01HND497T9JKR76MR3KA2CDJHP`) by adding the following condition:
6363

6464
```json
6565
"StringLike": {
66-
"demo.app.spacelift.io:sub": "space:production:*"
66+
"demo.app.spacelift.io:sub": "space:production-01HND497T9JKR76MR3KA2CDJHP:*"
6767
}
6868
```
6969

@@ -80,6 +80,11 @@ You can also restrict the role so only a specific stack can assume it, using the
8080

8181
You can mix and match these to get the exact constraints you need. You can learn more about the intricacies of AWS IAM conditions in the [official docs](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition.html){: rel="nofollow"}. Remember that AWS does not seem to support custom claims, so you will need to use the standard ones to do the matching (primarily `sub`, as shown above).
8282

83+
The full `sub` is constructed as follows:
84+
85+
* Format: `space:<space_id>:(stack|module):<stack_id|module_id>:run_type:<run_type>:scope:<read|write>`
86+
* For example: `space:legacy-01KJMM56VS4W3AL9YZWVCXBX8D:stack:infra:run_type:TRACKED:scope:write`
87+
8388
## Configure the Terraform provider
8489

8590
Once the Spacelift-AWS OIDC integration is set up, the Terraform provider can be configured without the need for any static credentials. The `aws_role_arn` variable should be set to the ARN of the role that you want to assume:

docs/integrations/cloud-providers/oidc/azure-oidc.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,21 @@ Take a look at the following screenshot for an example allowing a proposed run t
4343

4444
Workload federation in Azure requires the subject claim of the OIDC token to exactly match the federated credential, and doesn't allow wildcards. Because of this you will need to repeat the same process and add a number of different federated credentials in order to support all the different types of runs for your Stack or module.
4545

46-
For example, for a stack called `azure-oidc-test` in the `legacy` space you need to add credentials for the following subjects:
46+
For example, for a stack called `azure-oidc-test` in the `legacy` space (with space ID `legacy-01KJMM56VS4W3AL9YZWVCXBX8D`) you need to add credentials for the following subjects:
4747

4848
```text
49-
space:legacy:stack:azure-oidc-test:run_type:TRACKED:scope:read
50-
space:legacy:stack:azure-oidc-test:run_type:TRACKED:scope:write
51-
space:legacy:stack:azure-oidc-test:run_type:PROPOSED:scope:read
52-
space:legacy:stack:azure-oidc-test:run_type:TASK:scope:write
53-
space:legacy:stack:azure-oidc-test:run_type:DESTROY:scope:write
49+
space:legacy-01KJMM56VS4W3AL9YZWVCXBX8D:stack:azure-oidc-test:run_type:TRACKED:scope:read
50+
space:legacy-01KJMM56VS4W3AL9YZWVCXBX8D:stack:azure-oidc-test:run_type:TRACKED:scope:write
51+
space:legacy-01KJMM56VS4W3AL9YZWVCXBX8D:stack:azure-oidc-test:run_type:PROPOSED:scope:read
52+
space:legacy-01KJMM56VS4W3AL9YZWVCXBX8D:stack:azure-oidc-test:run_type:TASK:scope:write
53+
space:legacy-01KJMM56VS4W3AL9YZWVCXBX8D:stack:azure-oidc-test:run_type:DESTROY:scope:write
5454
```
5555

56-
And for a module called `my-module` in the `development` space you need to add the following:
56+
And for a module called `my-module` in the `development` space (with space ID `development-01JS2ABCDEFGHIJK123456789`) you need to add the following:
5757

5858
```text
59-
space:development:stack:my-module:run_type:TESTING:scope:read
60-
space:development:stack:my-module:run_type:TESTING:scope:write
59+
space:development-01JS2ABCDEFGHIJK123456789:stack:my-module:run_type:TESTING:scope:read
60+
space:development-01JS2ABCDEFGHIJK123456789:stack:my-module:run_type:TESTING:scope:write
6161
```
6262

6363
After adding all the credentials for a stack, it should look something like this:

0 commit comments

Comments
 (0)