Skip to content

Commit 166d8f6

Browse files
feat(ContainerAuthenticator): add support for code engine workload (#232)
Signed-off-by: Sascha Schwarze <[email protected]>
1 parent 5f103ea commit 166d8f6

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

Authentication.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,10 @@ ExampleService service = ExampleService.newInstance("example_service");
336336
## Container Authentication
337337
The `ContainerAuthenticator` is intended to be used by application code
338338
running inside a compute resource managed by the IBM Kubernetes Service (IKS)
339-
in which a secure compute resource token (CR token) has been stored in a file
340-
within the compute resource's local file system.
339+
or IBM Cloud Code Engine in which a secure compute resource token (CR token)
340+
has been stored in a file within the compute resource's local file system.
341341
The CR token is similar to an IAM apikey except that it is managed automatically by
342-
the compute resource provider (IKS).
342+
the compute resource provider (IKS or Code Engine).
343343
This allows the application developer to:
344344
- avoid storing credentials in application code, configuration files or a password vault
345345
- avoid managing or rotating credentials
@@ -359,7 +359,9 @@ The IAM access token is added to each outbound request in the `Authorization` he
359359

360360
- crTokenFilename: (optional) the name of the file containing the injected CR token value.
361361
If not specified, then the authenticator will first try `/var/run/secrets/tokens/vault-token`
362-
and then `/var/run/secrets/tokens/sa-token` as the default value (first file found is used).
362+
and then `/var/run/secrets/tokens/sa-token` and finally
363+
`/var/run/secrets/codeengine.cloud.ibm.com/compute-resource-token/token` as the default value
364+
(first file found is used).
363365
The application must have `read` permissions on the file containing the CR token value.
364366

365367
- iamProfileName: (optional) the name of the linked trusted IAM profile to be used when obtaining the

src/main/java/com/ibm/cloud/sdk/core/security/ContainerAuthenticator.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* (C) Copyright IBM Corp. 2021, 2024.
2+
* (C) Copyright IBM Corp. 2021, 2025.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -43,6 +43,8 @@ public class ContainerAuthenticator extends IamRequestBasedAuthenticator impleme
4343
private static final String OPERATION_PATH = "/identity/token";
4444
private static final String DEFAULT_CR_TOKEN_FILENAME1 = "/var/run/secrets/tokens/vault-token";
4545
private static final String DEFAULT_CR_TOKEN_FILENAME2 = "/var/run/secrets/tokens/sa-token";
46+
private static final String
47+
DEFAULT_CR_TOKEN_FILENAME3 = "/var/run/secrets/codeengine.cloud.ibm.com/compute-resource-token/token";
4648
private static final String ERRORMSG_CR_TOKEN_ERROR = "Error reading CR token file: %s";
4749

4850
// Properties specific to a ContainerAuthenticator.
@@ -385,11 +387,15 @@ protected String retrieveCRToken() {
385387
// Try to read from the file specified by the user.
386388
crToken = readFile(getCrTokenFilename());
387389
} else {
388-
// If no filename was supplied by the user, then try our two default filenames.
390+
// If no filename was supplied by the user, then try our three default filenames.
389391
try {
390392
crToken = readFile(DEFAULT_CR_TOKEN_FILENAME1);
391393
} catch (Throwable t) {
392-
crToken = readFile(DEFAULT_CR_TOKEN_FILENAME2);
394+
try {
395+
crToken = readFile(DEFAULT_CR_TOKEN_FILENAME2);
396+
} catch (Throwable t1) {
397+
crToken = readFile(DEFAULT_CR_TOKEN_FILENAME3);
398+
}
393399
}
394400
}
395401
return crToken;

0 commit comments

Comments
 (0)