|
| 1 | +# E2E Tests: OIDC Keyless Authentication Setup |
| 2 | + |
| 3 | +This guide explains how to configure GitHub Actions OIDC (OpenID Connect) for |
| 4 | +running E2E tests against Alibaba Cloud without storing long-lived AK/SK credentials. |
| 5 | + |
| 6 | +## How It Works |
| 7 | + |
| 8 | +``` |
| 9 | +GitHub Actions ──OIDC token──> Alibaba Cloud RAM (OIDC Provider) |
| 10 | + │ |
| 11 | + ▼ |
| 12 | + STS AssumeRoleWithOIDC |
| 13 | + │ |
| 14 | + ▼ |
| 15 | + Temporary AK/SK/SecurityToken |
| 16 | + │ |
| 17 | + ▼ |
| 18 | + E2E tests use temp creds |
| 19 | +``` |
| 20 | + |
| 21 | +1. GitHub Actions generates an OIDC token containing repository and workflow metadata. |
| 22 | +2. The `aliyun/configure-aliyun-credentials-action` exchanges that token with Alibaba Cloud STS. |
| 23 | +3. STS returns temporary credentials (valid for 1 hour) scoped to a specific RAM Role. |
| 24 | +4. E2E tests use those credentials — no permanent secrets stored anywhere. |
| 25 | + |
| 26 | +## Prerequisites |
| 27 | + |
| 28 | +- Alibaba Cloud account with RAM admin access |
| 29 | +- GitHub repository admin access (to configure secrets) |
| 30 | + |
| 31 | +## Step 1: Create OIDC Identity Provider in RAM |
| 32 | + |
| 33 | +1. Go to [RAM Console > SSO Management > OIDC](https://ram.console.aliyun.com/providers/oidc) |
| 34 | +2. Click **Create OIDC Provider** |
| 35 | +3. Fill in the form: |
| 36 | + |
| 37 | +| Field | Value | |
| 38 | +|-------|-------| |
| 39 | +| Provider Name | `github-actions` | |
| 40 | +| Issuer URL | `https://token.actions.githubusercontent.com` | |
| 41 | +| Client ID (Audience) | `sts.aliyuncs.com` | |
| 42 | +| Description | GitHub Actions OIDC for agentrun-sdk e2e tests | |
| 43 | + |
| 44 | +4. Click **OK** to create. |
| 45 | +5. Copy the **Provider ARN**, it looks like: |
| 46 | + ``` |
| 47 | + acs:ram::<ACCOUNT_ID>:oidc-provider/github-actions |
| 48 | + ``` |
| 49 | + |
| 50 | +## Step 2: Create a RAM Role for E2E Tests |
| 51 | + |
| 52 | +1. Go to [RAM Console > Identities > Roles](https://ram.console.aliyun.com/roles) |
| 53 | +2. Click **Create Role** > **IdP** > **OIDC** |
| 54 | +3. Fill in the form: |
| 55 | + |
| 56 | +| Field | Value | |
| 57 | +|-------|-------| |
| 58 | +| Role Name | `github-actions-e2e` | |
| 59 | +| Select OIDC Provider | `github-actions` (created in Step 1) | |
| 60 | +| Condition | See trust policy below | |
| 61 | + |
| 62 | +4. Use this **Trust Policy** (edit the role after creation if the console doesn't allow full customization): |
| 63 | + |
| 64 | +```json |
| 65 | +{ |
| 66 | + "Statement": [ |
| 67 | + { |
| 68 | + "Action": "sts:AssumeRoleWithOIDC", |
| 69 | + "Condition": { |
| 70 | + "StringEquals": { |
| 71 | + "oidc:aud": "sts.aliyuncs.com" |
| 72 | + }, |
| 73 | + "StringLike": { |
| 74 | + "oidc:sub": "repo:Serverless-Devs/agentrun-sdk-python:*" |
| 75 | + } |
| 76 | + }, |
| 77 | + "Effect": "Allow", |
| 78 | + "Principal": { |
| 79 | + "Federated": [ |
| 80 | + "acs:ram::<ACCOUNT_ID>:oidc-provider/github-actions" |
| 81 | + ] |
| 82 | + } |
| 83 | + } |
| 84 | + ], |
| 85 | + "Version": "1" |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +> Replace `<ACCOUNT_ID>` with your Alibaba Cloud account ID. |
| 90 | +> |
| 91 | +> The `oidc:sub` condition restricts access to this specific repository. |
| 92 | +> You can narrow it further: `repo:Serverless-Devs/agentrun-sdk-python:ref:refs/heads/main` |
| 93 | +> would limit to the main branch only. |
| 94 | +
|
| 95 | +5. Copy the **Role ARN**, it looks like: |
| 96 | + ``` |
| 97 | + acs:ram::<ACCOUNT_ID>:role/github-actions-e2e |
| 98 | + ``` |
| 99 | + |
| 100 | +## Step 3: Attach Permission Policy to the Role |
| 101 | + |
| 102 | +The RAM Role needs permissions to call AgentRun / Function Compute APIs |
| 103 | +used by the E2E tests. Create a custom policy or attach existing ones: |
| 104 | + |
| 105 | +**Recommended minimum permissions:** |
| 106 | +- `AliyunFCReadOnlyAccess` (read-only FC access for test verification) |
| 107 | +- A custom policy for AgentRun API operations used in tests |
| 108 | + |
| 109 | +Example custom policy: |
| 110 | +```json |
| 111 | +{ |
| 112 | + "Version": "1", |
| 113 | + "Statement": [ |
| 114 | + { |
| 115 | + "Effect": "Allow", |
| 116 | + "Action": [ |
| 117 | + "fc:*" |
| 118 | + ], |
| 119 | + "Resource": [ |
| 120 | + "acs:fc:<REGION>:<ACCOUNT_ID>:*" |
| 121 | + ] |
| 122 | + } |
| 123 | + ] |
| 124 | +} |
| 125 | +``` |
| 126 | + |
| 127 | +> Adjust the `Action` and `Resource` scope based on what your E2E tests actually call. |
| 128 | +> Principle of least privilege: grant only what the tests need. |
| 129 | +
|
| 130 | +## Step 4: Configure GitHub Secrets |
| 131 | + |
| 132 | +Go to **GitHub repo > Settings > Secrets and variables > Actions** and add: |
| 133 | + |
| 134 | +### OIDC Secrets (required for authentication) |
| 135 | + |
| 136 | +| Secret Name | Description | Example | |
| 137 | +|-------------|-------------|---------| |
| 138 | +| `ALIBABA_CLOUD_OIDC_PROVIDER_ARN` | OIDC Provider ARN from Step 1 | `acs:ram::1234567890:oidc-provider/github-actions` | |
| 139 | +| `ALIBABA_CLOUD_OIDC_ROLE_ARN` | RAM Role ARN from Step 2 | `acs:ram::1234567890:role/github-actions-e2e` | |
| 140 | + |
| 141 | +### Test Configuration Secrets (required for e2e tests) |
| 142 | + |
| 143 | +| Secret Name | Description | Example | |
| 144 | +|-------------|-------------|---------| |
| 145 | +| `AGENTRUN_ACCOUNT_ID` | Alibaba Cloud account ID | `1234567890` | |
| 146 | +| `AGENTRUN_REGION` | Region for test resources | `cn-hangzhou` | |
| 147 | +| `AGENTRUN_CONTROL_ENDPOINT` | AgentRun control API endpoint | `https://agentrun.cn-hangzhou.aliyuncs.com` | |
| 148 | +| `AGENTRUN_DATA_ENDPOINT` | AgentRun data API endpoint | `https://1234567890.agentrun-data.cn-hangzhou.aliyuncs.com` | |
| 149 | + |
| 150 | + |
| 151 | +> `API_KEY` and `AGENTRUN_TEST_WORKSPACE_ID` use hardcoded placeholders in the |
| 152 | +> workflow and do not need to be configured as secrets. |
| 153 | +
|
| 154 | +## Step 5: Verify |
| 155 | + |
| 156 | +1. Push a commit to `main` or trigger the workflow manually via **Actions > E2E Tests > Run workflow**. |
| 157 | +2. Check the workflow run — the "Configure Alibaba Cloud credentials (OIDC)" step should succeed. |
| 158 | +3. E2E tests should run with temporary credentials. |
| 159 | + |
| 160 | +## Troubleshooting |
| 161 | + |
| 162 | +### "AssumeRoleWithOIDC failed" |
| 163 | +- Verify the OIDC Provider issuer URL is exactly `https://token.actions.githubusercontent.com` |
| 164 | +- Verify the Role trust policy `oidc:sub` matches your repo: `repo:Serverless-Devs/agentrun-sdk-python:*` |
| 165 | +- Check the audience is `sts.aliyuncs.com` |
| 166 | + |
| 167 | +### "Permission denied" during tests |
| 168 | +- The RAM Role needs the right policies attached (Step 3) |
| 169 | +- Check if the region in the policy matches `AGENTRUN_REGION` |
| 170 | + |
| 171 | +### E2E tests skip on fork PRs |
| 172 | +- This is intentional: fork PRs cannot access OIDC secrets |
| 173 | +- Only PRs from the same repo, pushes to main, and manual triggers run e2e |
0 commit comments