Skip to content

Commit 3a51206

Browse files
committed
feat: introduce new container authenticator
This commit introduces the new ContainerAuthenticator class, along with associated tests and documentation. The ContainerAuthenticator implements the authentication flow to be used in IKS-managed compute resources where a secure compute resource token has been injected into the local file system by the IKS compute resource provider. The authenticator will read the cr token, then use it to obtain an IAM access token by invoking the IAM "get token" operation with grant-type "cr-token".
1 parent a44720b commit 3a51206

16 files changed

+1310
-80
lines changed

.secrets.baseline

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"files": "package-lock.json|^.secrets.baseline$",
44
"lines": null
55
},
6-
"generated_at": "2021-07-26T18:11:07Z",
6+
"generated_at": "2021-08-07T17:12:28Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"
@@ -25,6 +25,7 @@
2525
"name": "CloudantDetector"
2626
},
2727
{
28+
"ghe_instance": "github.ibm.com",
2829
"name": "GheDetector"
2930
},
3031
{
@@ -69,23 +70,23 @@
6970
"hashed_secret": "47fcf185ee7e15fe05cae31fbe9e4ebe4a06a40d",
7071
"is_secret": false,
7172
"is_verified": false,
72-
"line_number": 170,
73+
"line_number": 192,
7374
"type": "Secret Keyword",
7475
"verified_result": null
7576
},
7677
{
7778
"hashed_secret": "98635b2eaa2379f28cd6d72a38299f286b81b459",
7879
"is_secret": false,
7980
"is_verified": false,
80-
"line_number": 198,
81+
"line_number": 316,
8182
"type": "Secret Keyword",
8283
"verified_result": null
8384
},
8485
{
8586
"hashed_secret": "91dfd9ddb4198affc5c194cd8ce6d338fde470e2",
8687
"is_secret": false,
8788
"is_verified": false,
88-
"line_number": 226,
89+
"line_number": 348,
8990
"type": "Secret Keyword",
9091
"verified_result": null
9192
}
@@ -103,43 +104,43 @@
103104
"hashed_secret": "d4c3d66fd0c38547a3c7a4c6bdc29c36911bc030",
104105
"is_secret": false,
105106
"is_verified": false,
106-
"line_number": 42,
107+
"line_number": 43,
107108
"type": "Secret Keyword",
108109
"verified_result": null
109110
},
110111
{
111112
"hashed_secret": "8318df9ecda039deac9868adf1944a29a95c7114",
112113
"is_secret": false,
113114
"is_verified": false,
114-
"line_number": 44,
115+
"line_number": 45,
115116
"type": "Secret Keyword",
116117
"verified_result": null
117118
},
118119
{
119120
"hashed_secret": "9a66213cc16d178fdbf9f4da6b7bd92497fda404",
120121
"is_secret": false,
121122
"is_verified": false,
122-
"line_number": 50,
123+
"line_number": 51,
123124
"type": "Secret Keyword",
124125
"verified_result": null
125126
}
126127
],
127-
"src/main/java/com/ibm/cloud/sdk/core/security/IamAuthenticator.java": [
128+
"src/test/java/com/ibm/cloud/sdk/core/test/security/BasicAuthenticatorTest.java": [
128129
{
129-
"hashed_secret": "d4c3d66fd0c38547a3c7a4c6bdc29c36911bc030",
130+
"hashed_secret": "ffac6ba71b03ca5f5012197511d76fbcfcf62fbf",
130131
"is_secret": false,
131132
"is_verified": false,
132-
"line_number": 39,
133+
"line_number": 36,
133134
"type": "Secret Keyword",
134135
"verified_result": null
135136
}
136137
],
137-
"src/test/java/com/ibm/cloud/sdk/core/test/security/BasicAuthenticatorTest.java": [
138+
"src/test/java/com/ibm/cloud/sdk/core/test/security/ContainerAuthenticatorTest.java": [
138139
{
139-
"hashed_secret": "ffac6ba71b03ca5f5012197511d76fbcfcf62fbf",
140+
"hashed_secret": "360c23c1ac7d9d6dad1d0710606b0df9de6e1a18",
140141
"is_secret": false,
141142
"is_verified": false,
142-
"line_number": 36,
143+
"line_number": 64,
143144
"type": "Secret Keyword",
144145
"verified_result": null
145146
}
@@ -149,15 +150,15 @@
149150
"hashed_secret": "789cbe0407840b1c2041cb33452ff60f19bf58cc",
150151
"is_secret": false,
151152
"is_verified": false,
152-
"line_number": 63,
153+
"line_number": 62,
153154
"type": "Secret Keyword",
154155
"verified_result": null
155156
},
156157
{
157158
"hashed_secret": "2207d3f3ac68743290fe4affc71c10bec4962232",
158159
"is_secret": false,
159160
"is_verified": false,
160-
"line_number": 64,
161+
"line_number": 63,
161162
"type": "Secret Keyword",
162163
"verified_result": null
163164
}
@@ -167,7 +168,7 @@
167168
"hashed_secret": "ca3f35fa1a5cb92b242c2b42d6d902d43b4816f0",
168169
"is_secret": false,
169170
"is_verified": false,
170-
"line_number": 62,
171+
"line_number": 61,
171172
"type": "Secret Keyword",
172173
"verified_result": null
173174
}
@@ -255,7 +256,7 @@
255256
"hashed_secret": "e4f50034475acff058e17b35679f8ef1e54f86c5",
256257
"is_secret": false,
257258
"is_verified": false,
258-
"line_number": 73,
259+
"line_number": 85,
259260
"type": "Secret Keyword",
260261
"verified_result": null
261262
}
@@ -321,7 +322,7 @@
321322
}
322323
]
323324
},
324-
"version": "0.13.1+ibm.31.dss",
325+
"version": "0.13.1+ibm.40.dss",
325326
"word_list": {
326327
"file": null,
327328
"hash": null

Authentication.md

Lines changed: 127 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Authentication
22
The java-sdk-core project supports the following types of authentication:
33
- Basic Authentication
4-
- Bearer Token
5-
- Identity and Access Management (IAM)
6-
- Cloud Pak for Data
4+
- Bearer Token Authentication
5+
- Identity and Access Management (IAM) Authentication
6+
- Container Authentication
7+
- Cloud Pak for Data Authentication
78
- No Authentication
89

910
The SDK user configures the appropriate type of authentication for use with service instances.
@@ -23,15 +24,20 @@ configuration information. The configuration examples below will use
2324
environment variables, although the same properties could be specified in a
2425
credentials file instead.
2526

27+
2628
## Basic Authentication
2729
The `BasicAuthenticator` is used to add Basic Authentication information to
2830
each outbound request in the `Authorization` header in the form:
2931
```
3032
Authorization: Basic <encoded username and password>
3133
```
34+
3235
### Properties
36+
3337
- username: (required) the basic auth username
38+
3439
- password: (required) the basic auth password
40+
3541
### Programming example
3642
```java
3743
import com.ibm.cloud.sdk.core.security.BasicAuthenticator;
@@ -48,6 +54,7 @@ ExampleService service = new ExampleService(authenticator);
4854

4955
// 'service' can now be used to invoke operations.
5056
```
57+
5158
### Configuration example
5259
External configuration:
5360
```
@@ -69,14 +76,18 @@ ExampleService service = new ExampleService(authenticator);
6976
// 'service' can now be used to invoke operations.
7077
```
7178

79+
7280
## Bearer Token Authentication
7381
The `BearerTokenAuthenticator` will add a user-supplied bearer token to
7482
each outbound request in the `Authorization` header in the form:
7583
```
7684
Authorization: Bearer <bearer-token>
7785
```
86+
7887
### Properties
88+
7989
- bearerToken: (required) the bearer token value
90+
8091
### Programming example
8192
```java
8293
import com.ibm.cloud.sdk.core.security.BearerTokenAuthenticator;
@@ -96,6 +107,7 @@ ExampleService service = new ExampleService(authenticator);
96107
newToken = // ... obtain new bearer token value
97108
authenticator.setBearerToken(newToken);
98109
```
110+
99111
### Configuration example
100112
External configuration:
101113
```
@@ -120,13 +132,15 @@ ExampleService service = new ExampleService(authenticator);
120132
newToken = // ... obtain new bearer token value
121133
((BearerTokenAuthenticator) authenticator).setBearerToken(newToken);
122134
```
135+
123136
Note that the use of external configuration is not as useful with the `BearerTokenAuthenticator` as it
124137
is for other authenticator types because bearer tokens typically need to be obtained and refreshed
125138
programmatically since they normally have a relatively short lifespan before they expire. This
126139
authenticator type is intended for situations in which the application will be managing the bearer
127140
token itself in terms of initial acquisition and refreshing as needed.
128141

129-
## Identity and Access Management Authentication (IAM)
142+
143+
## Identity and Access Management (IAM) Authentication
130144
The `IamAuthenticator` will accept a user-supplied api key and will perform
131145
the necessary interactions with the IAM token service to obtain a suitable
132146
bearer token for the specified api key. The authenticator will also obtain
@@ -136,18 +150,25 @@ form:
136150
```
137151
Authorization: Bearer <bearer-token>
138152
```
153+
139154
### Properties
155+
140156
- apikey: (required) the IAM api key
157+
141158
- url: (optional) The URL representing the IAM token service endpoint. If not specified, a suitable
142159
default value is used.
160+
143161
- clientId/clientSecret: (optional) The `clientId` and `clientSecret` fields are used to form a
144162
"basic auth" Authorization header for interactions with the IAM token server. If neither field
145163
is specified, then no Authorization header will be sent with token server requests. These fields
146164
are optional, but must be specified together.
165+
147166
- disableSSLVerification: (optional) A flag that indicates whether verificaton of the server's SSL
148167
certificate should be disabled or not. The default value is `false`.
168+
149169
- headers: (optional) A set of key/value pairs that will be sent as HTTP headers in requests
150170
made to the IAM token service.
171+
151172
### Programming example
152173
```java
153174
import com.ibm.cloud.sdk.core.security.IamAuthenticator;
@@ -163,6 +184,7 @@ ExampleService service = new ExampleService(authenticator);
163184

164185
// 'service' can now be used to invoke operations.
165186
```
187+
166188
### Configuration example
167189
External configuration:
168190
```
@@ -183,7 +205,99 @@ ExampleService service = new ExampleService(authenticator);
183205
// 'service' can now be used to invoke operations.
184206
```
185207

186-
## Cloud Pak for Data
208+
209+
## Container Authentication
210+
The `ContainerAuthenticator` is intended to be used by application code
211+
running inside a compute resource managed by the IBM Kubernetes Service (IKS)
212+
in which a secure compute resource token (CR token) has been stored in a file
213+
within the compute resource's local file system.
214+
The CR token is similar to an IAM apikey except that it is managed automatically by
215+
the compute resource provider (IKS).
216+
This allows the application developer to:
217+
- avoid storing credentials in application code, configuraton files or a password vault
218+
- avoid managing or rotating credentials
219+
220+
The `ContainerAuthenticator` will retrieve the CR token from
221+
the compute resource in which the application is running, and will then perform
222+
the necessary interactions with the IAM token service to obtain an IAM access token
223+
using the IAM "get token" operation with grant-type `cr-token`.
224+
The authenticator will repeat these steps to obtain a new IAM access token when the
225+
current access token expires.
226+
The IAM access token is added to each outbound request in the `Authorization` header in the form:
227+
```
228+
Authorization: Bearer <IAM-access-token>
229+
```
230+
231+
### Properties
232+
233+
- crTokenFilename: (optional) the name of the file containing the injected CR token value.
234+
If not specified, then `/var/run/secrets/tokens/vault-token` is used as the default value.
235+
The application must have `read` permissions on the file containing the CR token value.
236+
237+
- iamProfileName: (optional) the name of the linked trusted IAM profile to be used when obtaining the
238+
IAM access token (a CR token might map to multiple IAM profiles).
239+
One of `iamProfileName` or `iamProfileID` must be specified.
240+
241+
- iamProfileID: (optional) the id of the linked trusted IAM profile to be used when obtaining the
242+
IAM access token (a CR token might map to multiple IAM profiles).
243+
One of `iamProfileName` or `iamProfileID` must be specified.
244+
245+
- url: (optional) The base endpoint URL of the IAM token service.
246+
The default value of this property is the "prod" IAM token service endpoint
247+
(`https://iam.cloud.ibm.com`).
248+
249+
- clientId/clientSecret: (optional) The `clientId` and `clientSecret` fields are used to form a
250+
"basic auth" Authorization header for interactions with the IAM token service. If neither field
251+
is specified, then no Authorization header will be sent with token server requests. These fields
252+
are optional, but must be specified together.
253+
254+
- scope: (optional) the scope to be associated with the IAM access token.
255+
If not specified, then no scope will be associated with the access token.
256+
257+
- disableSSLVerification: (optional) A flag that indicates whether verificaton of the server's SSL
258+
certificate should be disabled or not. The default value is `false`.
259+
260+
- headers: (optional) A set of key/value pairs that will be sent as HTTP headers in requests
261+
made to the IAM token service.
262+
263+
### Programming example
264+
```java
265+
import com.ibm.cloud.sdk.core.security.ContainerAuthenticator;
266+
import <sdk_base_package>.ExampleService.v1.ExampleService;
267+
...
268+
// Create the authenticator.
269+
ContainerAuthenticator authenticator = new ContainerAuthenticator.Builder()
270+
.iamProfileName("iam-user123")
271+
.build();
272+
273+
// Create the service instance.
274+
ExampleService service = new ExampleService(authenticator);
275+
276+
// 'service' can now be used to invoke operations.
277+
```
278+
279+
### Configuration example
280+
External configuration:
281+
```
282+
export EXAMPLE_SERVICE_AUTH_TYPE=container
283+
export EXAMPLE_SERVICE_IAM_PROFILE_NAME=iam-user123
284+
```
285+
Application code:
286+
```java
287+
import com.ibm.cloud.sdk.core.security.ConfigBaseAuthenticatorFactory;
288+
import <sdk_base_package>.ExampleService.v1.ExampleService;
289+
...
290+
// Create the authenticator.
291+
Authenticator authenticator = ConfigBasedAuthenticatorFactory.getAuthenticator("example_service");
292+
293+
// Create the service instance.
294+
ExampleService service = new ExampleService(authenticator);
295+
296+
// 'service' can now be used to invoke operations.
297+
```
298+
299+
300+
## Cloud Pak for Data Authentication
187301
The `CloudPakForDataAuthenticator` will accept user-supplied values for the username and either a password or apikey, and will
188302
perform the necessary interactions with the Cloud Pak for Data token service to obtain a suitable
189303
bearer token. The authenticator will also obtain a new bearer token when the current token expires.
@@ -192,15 +306,23 @@ form:
192306
```
193307
Authorization: Bearer <bearer-token>
194308
```
309+
195310
### Properties
311+
196312
- username: (required) the username used to obtain a bearer token.
313+
197314
- password: (required if apikey is not specified) the password used to obtain a bearer token.
315+
198316
- apikey: (required if password is not specified) the apikey used to obtain a bearer token.
317+
199318
- url: (required) The base URL associated with the Cloud Pak for Data token service.
319+
200320
- disableSSLVerification: (optional) A flag that indicates whether verificaton of the server's SSL
201321
certificate should be disabled or not. The default value is `false`.
322+
202323
- headers: (optional) A set of key/value pairs that will be sent as HTTP headers in requests
203324
made to the IAM token service.
325+
204326
### Programming example
205327
```java
206328
import com.ibm.cloud.sdk.core.security.CloudPakForDataAuthenticator;

0 commit comments

Comments
 (0)