Skip to content

Commit b6a4452

Browse files
authored
feat: Extract Credential from 'authorization' header and set it as 'A… (#93)
1 parent d98f852 commit b6a4452

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

charts/internal-gateway/files/conf.d/s3-gateway.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ server {
3232
proxy_read_timeout 60s;
3333
proxy_send_timeout 60s;
3434

35+
js_set $auth_header auth.setAuthHeader;
36+
37+
proxy_set_header Authorization $auth_header;
38+
3539
proxy_pass http://{{ index $vals "codefresh" "serviceEndpoints" "cfapi-auth" "svc" }}:{{ index $vals "codefresh" "serviceEndpoints" "cfapi-auth" "port" }};
3640
}
3741
}

charts/internal-gateway/files/njs/auth.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,21 @@ function account_name(r) {
22
const auth_entity = r.variables["auth_entity"];
33
const b64decoded = Buffer.from(auth_entity, 'base64');
44
const json = JSON.parse(b64decoded);
5-
const account_name = json.authenticatedEntity.activeAccount.name;
5+
const account_name = json.activeAccount.name;
66

77
return account_name;
88
}
99

10-
export default {account_name};
10+
function setAuthHeader(r) {
11+
let auth = r.headersIn['authorization'];
12+
if (auth) {
13+
// Look for the pattern: Credential=<value>/...
14+
let matches = auth.match(/Credential=([^\/]+)\//);
15+
if (matches && matches.length > 1) {
16+
return matches[1];
17+
}
18+
}
19+
return "";
20+
}
21+
22+
export default { account_name, setAuthHeader };

0 commit comments

Comments
 (0)