|
1 | 1 | package core |
2 | 2 |
|
3 | | -// (C) Copyright IBM Corp. 2021, 2024. |
| 3 | +// (C) Copyright IBM Corp. 2021, 2025. |
4 | 4 | // |
5 | 5 | // Licensed under the Apache License, Version 2.0 (the "License"); |
6 | 6 | // you may not use this file except in compliance with the License. |
@@ -29,16 +29,16 @@ import ( |
29 | 29 | ) |
30 | 30 |
|
31 | 31 | // ContainerAuthenticator implements an IAM-based authentication schema whereby it |
32 | | -// retrieves a "compute resource token" from the local compute resource (VM) |
| 32 | +// retrieves a "compute resource token" from the local compute resource (IKS pod, or Code Engine application, function, or job) |
33 | 33 | // and uses that to obtain an IAM access token by invoking the IAM "get token" operation with grant-type=cr-token. |
34 | 34 | // The resulting IAM access token is then added to outbound requests in an Authorization header |
35 | 35 | // of the form: |
36 | 36 | // |
37 | 37 | // Authorization: Bearer <access-token> |
38 | 38 | type ContainerAuthenticator struct { |
39 | 39 | // [optional] The name of the file containing the injected CR token value (applies to |
40 | | - // IKS-managed compute resources). |
41 | | - // Default value: (1) "/var/run/secrets/tokens/vault-token" or (2) "/var/run/secrets/tokens/sa-token", |
| 40 | + // IKS-managed compute resources, a Code Engine compute resource always uses the third default from below). |
| 41 | + // Default value: (1) "/var/run/secrets/tokens/vault-token" or (2) "/var/run/secrets/tokens/sa-token" or (3) "/var/run/secrets/codeengine.cloud.ibm.com/compute-resource-token/token", |
42 | 42 | // whichever is found first. |
43 | 43 | CRTokenFilename string |
44 | 44 |
|
@@ -98,9 +98,10 @@ type ContainerAuthenticator struct { |
98 | 98 | } |
99 | 99 |
|
100 | 100 | const ( |
101 | | - defaultCRTokenFilename1 = "/var/run/secrets/tokens/vault-token" // #nosec G101 |
102 | | - defaultCRTokenFilename2 = "/var/run/secrets/tokens/sa-token" // #nosec G101 |
103 | | - iamGrantTypeCRToken = "urn:ibm:params:oauth:grant-type:cr-token" // #nosec G101 |
| 101 | + defaultCRTokenFilename1 = "/var/run/secrets/tokens/vault-token" // #nosec G101 |
| 102 | + defaultCRTokenFilename2 = "/var/run/secrets/tokens/sa-token" // #nosec G101 |
| 103 | + defaultCRTokenFilename3 = "/var/run/secrets/codeengine.cloud.ibm.com/compute-resource-token/token" // #nosec G101 |
| 104 | + iamGrantTypeCRToken = "urn:ibm:params:oauth:grant-type:cr-token" // #nosec G101 |
104 | 105 | ) |
105 | 106 |
|
106 | 107 | var craRequestTokenMutex sync.Mutex |
@@ -504,6 +505,9 @@ func (authenticator *ContainerAuthenticator) retrieveCRToken() (crToken string, |
504 | 505 | crToken, err = authenticator.readFile(defaultCRTokenFilename1) |
505 | 506 | if err != nil { |
506 | 507 | crToken, err = authenticator.readFile(defaultCRTokenFilename2) |
| 508 | + if err != nil { |
| 509 | + crToken, err = authenticator.readFile(defaultCRTokenFilename3) |
| 510 | + } |
507 | 511 | } |
508 | 512 | } |
509 | 513 |
|
|
0 commit comments