Skip to content

Commit 6753d23

Browse files
Merge pull request #2 from cloudsmith-io/ceng-437-gha-allow-oidc-auth-only-without-installation
CENG-437: Add the ability to auth via oidc only
2 parents 313ef9f + 0ae4e95 commit 6753d23

File tree

6 files changed

+80
-9
lines changed

6 files changed

+80
-9
lines changed

.github/workflows/test_install.yml

+41
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,44 @@ jobs:
6969
Write-Output "Config file not found at $configFile"
7070
}
7171
shell: pwsh
72+
73+
test-oidc-only:
74+
runs-on: ubuntu-latest
75+
steps:
76+
- uses: actions/checkout@v4
77+
78+
- name: "Set up Node.js"
79+
uses: actions/setup-node@v4
80+
with:
81+
node-version: "20"
82+
83+
- name: "Install dependencies"
84+
run: npm install
85+
86+
- name: "Build project"
87+
run: npm run build
88+
89+
- name: OIDC Authentication Only
90+
uses: ./
91+
with:
92+
oidc-namespace: ${{ vars.NAMESPACE }}
93+
oidc-service-slug: ${{ vars.SERVICE_ACCOUNT }}
94+
oidc-auth-only: 'true'
95+
96+
- name: Test Authentication
97+
run: |
98+
curl -X GET \
99+
-H "Authorization: Bearer $CLOUDSMITH_API_KEY" \
100+
https://api.cloudsmith.io/v1/user/self/ \
101+
| jq -r '.authenticated'
102+
103+
- name: Test CLI Installation should fail
104+
id: cli-test
105+
continue-on-error: true
106+
run: cloudsmith --version
107+
108+
- name: Verify CLI installation failed
109+
if: steps.cli-test.outcome == 'success'
110+
run: |
111+
echo "CLI installation should have failed but succeeded"
112+
exit 1

README.md

+22-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This GitHub Action installs the Cloudsmith CLI and pre-authenticates it using OI
1010
- [`api-key`](action.yml): API Key for Cloudsmith (optional). 🔑
1111
- [`oidc-namespace`](action.yml): Cloudsmith organisation/namespace for OIDC (optional). 🌐
1212
- [`oidc-service-slug`](action.yml): Cloudsmith service account slug for OIDC (optional). 🐌
13+
- [`oidc-auth-only`](action.yml): Only perform OIDC authentication without installing the CLI (optional, default: false). 🔐
1314
- [`pip-install`](action.yml): Install the Cloudsmith CLI via pip (optional). 🐍
1415
- [`executable-path`](action.yml): Path to the Cloudsmith CLI executable (optional, default: `GITHUB_WORKSPACE/bin/`). 🛠️
1516

@@ -25,7 +26,7 @@ This GitHub Action installs the Cloudsmith CLI and pre-authenticates it using OI
2526
Cloudsmith OIDC [documentation](https://help.cloudsmith.io/docs/openid-connect) 📚
2627

2728
```yaml
28-
uses: cloudsmith-io/[email protected].1
29+
uses: cloudsmith-io/[email protected].2
2930
with:
3031
oidc-namespace: 'your-oidc-namespace'
3132
oidc-service-slug: 'your-service-account-slug'
@@ -36,11 +37,28 @@ with:
3637
Personal API Key can be found [here](https://cloudsmith.io/user/settings/api/), for CI-CD deployments we recommend using [Service Accounts](https://help.cloudsmith.io/docs/service-accounts). 🔒
3738
3839
```yaml
39-
uses: cloudsmith-io/[email protected].1
40+
uses: cloudsmith-io/[email protected].2
4041
with:
4142
api-key: 'your-api-key'
4243
```
4344
45+
## Example Usage with OIDC Authentication Only
46+
47+
If you only need to authenticate with Cloudsmith's API without installing the CLI:
48+
49+
```yaml
50+
uses: cloudsmith-io/[email protected]
51+
with:
52+
oidc-namespace: 'your-oidc-namespace'
53+
oidc-service-slug: 'your-service-account-slug'
54+
oidc-auth-only: 'true'
55+
```
56+
57+
This will:
58+
- Perform OIDC authentication
59+
- Set the OIDC token as `CLOUDSMITH_API_KEY` environment variable
60+
- Skip CLI installation
61+
4462
## Cloudsmith CLI Commands
4563

4664
Full CLI feature list can be found [here](https://github.com/cloudsmith-io/cloudsmith-cli?tab=readme-ov-file#features) 📖
@@ -68,7 +86,7 @@ jobs:
6886
uses: actions/checkout@v4
6987
7088
- name: Install Cloudsmith CLI
71-
uses: cloudsmith-io/[email protected].1
89+
uses: cloudsmith-io/[email protected].2
7290
with:
7391
oidc-namespace: 'your-oidc-namespace'
7492
oidc-service-slug: 'your-service-account-slug'
@@ -77,7 +95,6 @@ jobs:
7795
run: |
7896
cloudsmith push python your-namespace/your-repository dist/*.tar.gz
7997
```
80-
8198
## Contribution
8299

83100
Please check our [CONTRIBUTION](CONTRIBUTION.md) doc for more information. 🤝
@@ -89,3 +106,4 @@ This project is licensed under the MIT License - see the LICENSE file for detail
89106
## Support
90107

91108
If you have any questions or need further assistance, please open an issue on GitHub. We're here to help! 💬 Alternatively, you can contact us at [support.cloudsmith.com](https://support.cloudsmith.com/).
109+

action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ inputs:
1818
description: 'Cloudsmith service account slug for OIDC'
1919
default: ''
2020
required: false
21+
oidc-auth-only:
22+
description: 'Only perform OIDC authentication without installing the CLI'
23+
default: 'false'
24+
required: false
2125
pip-install:
2226
description: 'Install the Cloudsmith CLI via pip'
2327
default: 'false'

dist/index.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -43073,8 +43073,12 @@ async function run() {
4307343073
throw new Error("Either API key or OIDC inputs (namespace and service account slug) must be provided for authentication.");
4307443074
}
4307543075

43076-
// Install the CLI
43077-
await installCli();
43076+
// Install the CLI only if oidc-auth-only is false
43077+
const oidcAuthOnly = core.getBooleanInput('oidc-auth-only');
43078+
if (!oidcAuthOnly) {
43079+
await installCli();
43080+
}
43081+
4307843082
} catch (error) {
4307943083
core.setFailed(`Action failed: ${error.message}`);
4308043084
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cloudsmith-github-action",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "A GitHub Action to install Cloudsmith CLI and authenticate using OIDC",
55
"main": "dist/index.js",
66
"scripts": {

src/main.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ async function run() {
3131
throw new Error("Either API key or OIDC inputs (namespace and service account slug) must be provided for authentication.");
3232
}
3333

34-
// Install the CLI
35-
await installCli();
34+
// Install the CLI only if oidc-auth-only is false
35+
const oidcAuthOnly = core.getBooleanInput('oidc-auth-only');
36+
if (!oidcAuthOnly) {
37+
await installCli();
38+
}
39+
3640
} catch (error) {
3741
core.setFailed(`Action failed: ${error.message}`);
3842
}

0 commit comments

Comments
 (0)