Skip to content

Commit f89284f

Browse files
authored
Merge pull request #9 from alliander-opensource/update-denpendabot-alert
Update denpendabot alert
2 parents 717da35 + 204d55c commit f89284f

File tree

5 files changed

+3698
-3357
lines changed

5 files changed

+3698
-3357
lines changed

README.md

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# Use IAM roles to authenticate principals in workloads outside of AWS using JWT
2+
23
There is an inherent risk in maintaining and storing permanent credentials. In their lifetime, they are bound to be shared, compromised, and lost. When shared, it is often among a broader audience than initially intended. They can also be lost and found, sometimes by the wrong person. And when any of this occurs, it can put your systems, data or even organization at risk.
34

45
Workloads running on AWS can communicate with each other or with AWS services without the need of storing permanent credentials by assuming roles or instance profiles. However, if one of the workloads lives outside of AWS, AWS principals can no longer be used for authentication.
56

67
An alternative to authenticating with external workloads is to use short-lived credentials issued by a trusted party, the issuer, that the target system can accept. JWTs (JSON Web Tokens), as used by the OIDC (OpenID Connect) standard, are an example of such credentials. JWTs are short-lived credentials that can be signed and verified using a public key in what is known as public-key cryptography.
78

89
## Secure Token Service (STS)
10+
911
Exchanging credentials from on form to the other is done with a Secure Token Service (STS) function. AWS also provides STS functions not the one we need. Only the other way around: to exchange a JWT to IAM Session which is called [AssumeRoleWithWebIdentity](https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRoleWithWebIdentity.html).
1012
This repo contains a CDK Construct which will deploy a new function which adds the function to exchange an AWS IAM (Session) credential with a signed JWT.
1113

@@ -21,13 +23,13 @@ On time based events, EventBridge will trigger a Step function rotation flow. Th
2123

2224
## Using the construct
2325

24-
1. Init a new typescript CDK project
26+
1. Init a new typescript CDK project
2527
`cdk init app --language typescript`
26-
2. Config npm to retrieve packages from github package repository
28+
2. Config npm to retrieve packages from github package repository
2729
`echo @alliander-opensource:registry=https://npm.pkg.github.com > .npmrc`
28-
3. Install the aws-jwt-sts construct
30+
3. Install the aws-jwt-sts construct
2931
`npm install @alliander-opensource/aws-jwt-sts`
30-
4. Edit lib/my-sts-stack.ts to add the construct to the stack
32+
4. Edit lib/my-sts-stack.ts to add the construct to the stack
3133
See the comments in the code for possible options
3234

3335
```ts
@@ -102,6 +104,7 @@ export class MyStsStack extends cdk.Stack {
102104
The stack outputs the urls of the endpoints. So if no custom domain is provided observe the CDK Stack output.
103105

104106
## Using the STS function
107+
105108
A token from the STS function can be obained by invoking the token endpoint.
106109
`GET https://$host/token`
107110
optionally an audience can be provided if this needs to be different than the installed default
@@ -110,6 +113,7 @@ optionally an audience can be provided if this needs to be different than the in
110113
> Note: The IAM Role / User invoking the endpoint must have *execute-api:Invoke* permissions
111114
112115
In CDK these permission is added as followed:
116+
113117
```ts
114118
role.addToPolicy(new iam.PolicyStatement({
115119
actions: ['execute-api:Invoke'],
@@ -120,11 +124,13 @@ role.addToPolicy(new iam.PolicyStatement({
120124
> Note: keep in mind that *resource '\*'* should only be used if no other API GW's with IAM auth are used in that account.
121125
122126
### Test obtaining a JWT
123-
1. Ensure the AWS IAM Role / User invoking the token endpoint has execute-api permissions. If you are using administrator access then that is more than sufficient.
124-
2. Use a shell with AWS cli logged in, you can use your cli with which you deployed the stack or use cloudshell for this.
125-
3. Install awscurl for authentication
127+
128+
1. Ensure the AWS IAM Role / User invoking the token endpoint has execute-api permissions. If you are using administrator access then that is more than sufficient.
129+
2. Use a shell with AWS cli logged in, you can use your cli with which you deployed the stack or use cloudshell for this.
130+
3. Install awscurl for authentication
126131
`pip3 install awscurl`
127-
4. Install jwt-cli for jwt formatting
132+
4. Install jwt-cli for jwt formatting
128133
`npm install -g jwt-cli`
129-
5. Invoke the api: `awscurl {your token endpoint}/token --service execute-api --region {your_region} | jq -r .token | jwt decode – `
130-
6. Observe the JWT
134+
5. Invoke the api
135+
`awscurl {your_token_endpoint}/token --service execute-api --region {your_region} | jq -r .token | jwt decode –`
136+
6. Observe the JWT

0 commit comments

Comments
 (0)