Skip to content

Commit 546ad44

Browse files
committed
provenance by default
1 parent 83ef001 commit 546ad44

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lib/utils/oidc.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,29 @@ async function oidc ({ packageName, registry, opts, config }) {
116116
return undefined
117117
}
118118

119+
const [headerB64, payloadB64] = idToken.split('.')
120+
let isPublicRepo = false
121+
if (headerB64 && payloadB64) {
122+
const payloadJson = Buffer.from(payloadB64, 'base64').toString('utf8')
123+
try {
124+
const payload = JSON.parse(payloadJson)
125+
if (ciInfo.GITHUB_ACTIONS && payload.repository_visibility) {
126+
isPublicRepo = payload.repository_visibility
127+
}
128+
if (ciInfo.GITLAB && payload.project_visibility) {
129+
isPublicRepo = payload.project_visibility
130+
}
131+
} catch (e) {
132+
log.silly('oidc', 'Failed to parse idToken payload as JSON')
133+
}
134+
}
135+
136+
if (isPublicRepo) {
137+
log.silly('oidc', 'Repository is public, setting access to public')
138+
opts.provenance = true
139+
config.set('provenance', true, 'user')
140+
}
141+
119142
log.silly('oidc', `id_token has a length of ${idToken.length} characters`)
120143

121144
const parsedRegistry = new URL(registry)
@@ -157,6 +180,7 @@ async function oidc ({ packageName, registry, opts, config }) {
157180
opts[authTokenKey] = response.token
158181
config.set(authTokenKey, response.token, 'user')
159182
log.silly('oidc', `OIDC token successfully retrieved`)
183+
160184
} catch (error) {
161185
/* istanbul ignore next */
162186
log.verbose('oidc', 'Failure checking OIDC config', error)

0 commit comments

Comments
 (0)