-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d86986b
commit c67f21a
Showing
8 changed files
with
132 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,9 @@ on: | |
pull_request: | ||
branches: [ master ] | ||
|
||
permissions: | ||
id-token: write | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
@@ -34,11 +37,29 @@ jobs: | |
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} # required | ||
|
||
- name: Setup OIDC | ||
run: npm install @actions/[email protected] @actions/http-client | ||
|
||
- name: Get Id Token | ||
uses: actions/github-script@v7 | ||
id: idtoken | ||
with: | ||
script: | | ||
const coreDemo = require('@actions/core'); | ||
const idToken = await coreDemo.getIDToken('sts.aliyuncs.com'); | ||
const fsx = require('fs/promises'); | ||
await fsx.writeFile('/tmp/oidc_token', idToken); | ||
- name: Integration Test | ||
run: test -z $SUB_ACCESS_KEY_ID -a -z $SUB_ACCESS_KEY_SECRET || npm run test-integration | ||
run: npm run integration | ||
if: env.SUB_ACCESS_KEY_ID != '' | ||
env: | ||
# for RAM role ARN | ||
ROLE_ARN: ${{ secrets.ROLE_ARN }} | ||
SUB_ACCESS_KEY_ID: ${{ secrets.SUB_ACCESS_KEY_ID }} | ||
SUB_ACCESS_KEY_SECRET: ${{ secrets.SUB_ACCESS_KEY_SECRET }} | ||
ROLE_ARN_TO_ASSUME: ${{ secrets.ROLE_ARN_TO_ASSUME }} | ||
|
||
# for OIDC | ||
ALIBABA_CLOUD_OIDC_PROVIDER_ARN: ${{ secrets.ALIBABA_CLOUD_OIDC_PROVIDER_ARN }} | ||
ALIBABA_CLOUD_OIDC_TOKEN_FILE: "/tmp/oidc_token" | ||
ALIBABA_CLOUD_ROLE_ARN: ${{ secrets.OIDC_ROLE_ARN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import assert from 'assert'; | ||
import 'mocha'; | ||
import CredentialsClient, { Config } from '../src/client'; | ||
|
||
describe('credentials', () => { | ||
it('RAM Role ARN should ok with ak', async function () { | ||
const config = new Config({ | ||
type: 'ram_role_arn', | ||
roleArn: process.env.ROLE_ARN, | ||
accessKeyId: process.env.SUB_ACCESS_KEY_ID, | ||
accessKeySecret: process.env.SUB_ACCESS_KEY_SECRET | ||
}); | ||
|
||
const client = new CredentialsClient(config, {}); | ||
assert.strictEqual(client.getType(), 'ram_role_arn') | ||
const credentials = await client.getCredential(); | ||
assert.ok(credentials); | ||
assert.strictEqual(credentials.type, 'ram_role_arn'); | ||
assert.ok(credentials.securityToken); | ||
}); | ||
|
||
it('RAM Role ARN should ok with sts', async function () { | ||
const client = new CredentialsClient(new Config({ | ||
type: 'ram_role_arn', | ||
roleArn: process.env.ROLE_ARN, | ||
accessKeyId: process.env.SUB_ACCESS_KEY_ID, | ||
accessKeySecret: process.env.SUB_ACCESS_KEY_SECRET | ||
})); | ||
|
||
const credentials = await client.getCredential(); | ||
assert.ok(credentials); | ||
assert.strictEqual(credentials.type, 'ram_role_arn'); | ||
assert.ok(credentials.securityToken); | ||
|
||
// assume anothor role | ||
const config = new Config({ | ||
type: 'ram_role_arn', | ||
roleArn: process.env.ROLE_ARN_TO_ASSUME, | ||
accessKeyId: credentials.accessKeyId, | ||
accessKeySecret: credentials.accessKeySecret, | ||
securityToken: credentials.securityToken | ||
}); | ||
const client2 = new CredentialsClient(config); | ||
assert.strictEqual(client2.getType(), 'ram_role_arn') | ||
const credentials2 = await client2.getCredential(); | ||
assert.ok(credentials2); | ||
assert.strictEqual(credentials2.type, 'ram_role_arn'); | ||
assert.ok(credentials2.securityToken); | ||
}); | ||
|
||
it('OIDC should ok', async function() { | ||
const config = new Config({ | ||
type: 'oidc_role_arn', | ||
roleArn: process.env.ALIBABA_CLOUD_ROLE_ARN, | ||
oidcProviderArn: process.env.ALIBABA_CLOUD_OIDC_PROVIDER_ARN, | ||
oidcTokenFilePath: process.env.ALIBABA_CLOUD_OIDC_TOKEN_FILE, | ||
roleSessionName: 'credentials-go-test' | ||
}); | ||
const client = new CredentialsClient(config, {}); | ||
assert.strictEqual(client.getType(), 'oidc_role_arn') | ||
const credentials = await client.getCredential(); | ||
assert.ok(credentials); | ||
assert.strictEqual(credentials.type, 'oidc_role_arn'); | ||
assert.ok(credentials.securityToken); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters