@intentius/behold 0.32.0 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +64 -3133
- package/README.md +17 -6
- package/dist/chant-KLLNQOCK.js +117 -0
- package/dist/choudoufu-chant-read-MJ6DK23L.js +36 -0
- package/dist/chunk-26K6QLVB.js +157 -0
- package/dist/chunk-4IETG5U7.js +267 -0
- package/dist/chunk-7DQDWJI5.js +46 -0
- package/dist/chunk-ANJ33KX4.js +78 -0
- package/dist/chunk-C7OMVDI5.js +124 -0
- package/dist/chunk-GG3SLEYM.js +30297 -0
- package/dist/chunk-GMCRBXPQ.js +15578 -0
- package/dist/chunk-IMX6PXXA.js +1019 -0
- package/dist/chunk-JHLNY324.js +232 -0
- package/dist/chunk-JJPU2DXX.js +54 -0
- package/dist/chunk-KUHU6T4P.js +2820 -0
- package/dist/chunk-OY4EF7ZO.js +5651 -0
- package/dist/chunk-XKWCGNT2.js +8139 -0
- package/dist/chunk-YO233FHU.js +136 -0
- package/dist/cli.js +859 -77499
- package/dist/config-XKQQ4ORG.js +69 -0
- package/dist/config-run-4IMSAYPX.js +418 -0
- package/dist/declaration-5NE7H5UD.js +6867 -0
- package/dist/index.js +99 -0
- package/dist/main-4PGA5RJS.js +2509 -0
- package/dist/mcp-W2CHVEPI.js +753 -0
- package/dist/object-store-H77QSRIZ.js +1033 -0
- package/dist/src-54PT4UC5.js +1189 -0
- package/dist/tree-W23HE2EZ.js +17 -0
- package/example-choudoufu-estate/chant.workspace.json +1 -1
- package/example-terraform-estate/README.md +2 -2
- package/example-terraform-estate/chant.workspace.json +1 -1
- package/example-three-cloud/chant.workspace.json +2 -2
- package/example-three-cloud/package-lock.json +32 -515
- package/example-three-cloud/package.json +5 -5
- package/package.json +18 -16
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// node_modules/@intentius/chant/dist/ci-identity.js
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
var CLOUDS = ["aws", "gcp", "azure"];
|
|
4
|
+
var IDENTITY_CLOUDS = [...CLOUDS, "pulumi"];
|
|
5
|
+
var AZURE_DATABASE_SCOPE = "https://ossrdbms-aad.database.windows.net/.default";
|
|
6
|
+
var AZURE_DATABASE_TOKEN_ENV = "AZURE_DATABASE_ACCESS_TOKEN";
|
|
7
|
+
var IDENTITY_KEY = { aws: "role", gcp: "serviceAccount", azure: "clientId", pulumi: "token" };
|
|
8
|
+
function cloudIdentityProblems(decl) {
|
|
9
|
+
const out = [];
|
|
10
|
+
for (const cloud of IDENTITY_CLOUDS) {
|
|
11
|
+
const rules = decl[cloud]?.rules ?? [];
|
|
12
|
+
const applies = new Set(rules.map((r) => r.apply));
|
|
13
|
+
rules.forEach((r, i) => {
|
|
14
|
+
const pointer = `/ci/identity/cloud/${cloud}/rules/${i}`;
|
|
15
|
+
if (r.plan === r.apply)
|
|
16
|
+
out.push({ pointer, message: `ci.identity.cloud.${cloud}.rules[${i}] plans and applies as ${r.plan}; the plan runs the pull request's code, so give it an identity of its own` });
|
|
17
|
+
else if (applies.has(r.plan))
|
|
18
|
+
out.push({ pointer, message: `ci.identity.cloud.${cloud}.rules[${i}] plans as ${r.plan}, which another rule applies as; the plan runs the pull request's code, so give it an identity no rule applies as` });
|
|
19
|
+
if (cloud === "pulumi") {
|
|
20
|
+
for (const side of ["plan", "apply"]) {
|
|
21
|
+
if (!pulumiTokenRequest(r[side]))
|
|
22
|
+
out.push({ pointer: `${pointer}/${side}`, message: `ci.identity.cloud.pulumi.rules[${i}].${side} is ${JSON.stringify(r[side])}; a Pulumi Cloud identity is team:<name>, user:<login>, organization or organization:admin` });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
function pulumiTokenRequest(identity) {
|
|
30
|
+
const m = /^(team|user):([^\s:]+)$/.exec(identity);
|
|
31
|
+
if (m)
|
|
32
|
+
return { tokenType: `urn:pulumi:token-type:access_token:${m[1] === "team" ? "team" : "personal"}`, scope: identity };
|
|
33
|
+
if (identity === "organization")
|
|
34
|
+
return { tokenType: "urn:pulumi:token-type:access_token:organization" };
|
|
35
|
+
if (identity === "organization:admin")
|
|
36
|
+
return { tokenType: "urn:pulumi:token-type:access_token:organization", scope: "admin" };
|
|
37
|
+
return void 0;
|
|
38
|
+
}
|
|
39
|
+
var TRADE_SPEC_ENV = "CHANT_CLOUD_TRADE";
|
|
40
|
+
function idTokenVar(cloud) {
|
|
41
|
+
return `CHANT_ID_TOKEN_${cloud.toUpperCase()}`;
|
|
42
|
+
}
|
|
43
|
+
var OIDC_REQUEST_VARS = ["ACTIONS_ID_TOKEN_REQUEST_TOKEN", "ACTIONS_ID_TOKEN_REQUEST_URL", ...IDENTITY_CLOUDS.map(idTokenVar), TRADE_SPEC_ENV];
|
|
44
|
+
var CLOUD_TARGETS_ENV = "CHANT_CLOUD_TARGETS";
|
|
45
|
+
var CLOUD_TRADED_ENV = "CHANT_CLOUD_TRADED";
|
|
46
|
+
var TRADE_JS = [
|
|
47
|
+
'const fs=require("fs");',
|
|
48
|
+
"const [out,format]=process.argv.slice(1);",
|
|
49
|
+
"const Q=String.fromCharCode(39);",
|
|
50
|
+
'const fail=(m)=>{console.error("chant: the OIDC trade failed: "+m);process.exit(1)};',
|
|
51
|
+
`let spec;try{spec=JSON.parse(process.env.${TRADE_SPEC_ENV}||"")}catch{fail("${TRADE_SPEC_ENV} is not JSON")}`,
|
|
52
|
+
'const clean=(v)=>typeof v==="string"&&/^[\\x21-\\x7e]+$/.test(v);',
|
|
53
|
+
'const trim=(u)=>String(u).replace(/\\/+$/,"");',
|
|
54
|
+
'const post=async(url,headers,body)=>{const r=await fetch(url,{method:"POST",headers,body});const t=await r.text();if(!r.ok)throw new Error(url+" answered "+r.status+": "+t.slice(0,200).replace(/\\s+/g," "));return t};',
|
|
55
|
+
'const json=(t,what)=>{try{return JSON.parse(t)}catch{throw new Error(what+" answered with no JSON")}};',
|
|
56
|
+
"const idToken=async(cloud,aud)=>{",
|
|
57
|
+
'const named=process.env["CHANT_ID_TOKEN_"+cloud.toUpperCase()];if(named)return named;',
|
|
58
|
+
"const u=process.env.ACTIONS_ID_TOKEN_REQUEST_URL,k=process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN;",
|
|
59
|
+
'if(!u||!k)throw new Error("the job can request no OIDC token for "+cloud+": it needs id-token: write, and a pull request from a fork gets none");',
|
|
60
|
+
'const r=await fetch(u+(u.includes("?")?"&":"?")+"audience="+encodeURIComponent(aud),{headers:{authorization:"bearer "+k,accept:"application/json"}});',
|
|
61
|
+
'if(!r.ok)throw new Error("the OIDC token request answered "+r.status);',
|
|
62
|
+
'const v=json(await r.text(),"the OIDC token request").value;if(!clean(v))throw new Error("the OIDC token request gave no token");return v};',
|
|
63
|
+
`const KEY=${JSON.stringify(IDENTITY_KEY)};`,
|
|
64
|
+
// #4332: a cloud's identities, its own first, then its targets', once each.
|
|
65
|
+
'const ids=(c)=>{const s=spec[c],l=[];if(s[KEY[c]])l.push(s[KEY[c]]);for(const t of s.targets||[])if(!l.includes(t[KEY[c]]))l.push(t[KEY[c]]);if(!l.length)throw new Error(c+" names no identity");return l};',
|
|
66
|
+
"const vars={},secrets=[],said=[],by={};",
|
|
67
|
+
"const run=async()=>{",
|
|
68
|
+
'if(spec.aws){const a=spec.aws;const tok=await idToken("aws",a.audience);by.aws={};',
|
|
69
|
+
'const ep=trim(a.endpoint||process.env.AWS_ENDPOINT_URL_STS||("https://sts."+a.region+".amazonaws.com"+(a.region.startsWith("cn-")?".cn":"")));',
|
|
70
|
+
'for(const role of ids("aws")){',
|
|
71
|
+
'const t=await post(ep+"/",{"content-type":"application/x-www-form-urlencoded",accept:"application/xml"},new URLSearchParams({Action:"AssumeRoleWithWebIdentity",Version:"2011-06-15",RoleArn:role,RoleSessionName:"chant-"+(process.env.GITHUB_RUN_ID||process.env.CI_JOB_ID||"job"),WebIdentityToken:tok}).toString());',
|
|
72
|
+
'const g=(k)=>{const m=new RegExp("<"+k+">([^<]+)</"+k+">").exec(t);return m?m[1].trim():undefined};',
|
|
73
|
+
'const id=g("AccessKeyId"),key=g("SecretAccessKey"),st=g("SessionToken");if(!clean(id)||!clean(key)||!clean(st))throw new Error("STS gave no credentials for "+role);',
|
|
74
|
+
"by.aws[role]={AWS_ACCESS_KEY_ID:id,AWS_SECRET_ACCESS_KEY:key,AWS_SESSION_TOKEN:st,AWS_REGION:a.region,AWS_DEFAULT_REGION:a.region};secrets.push(key,st);said.push(role)}",
|
|
75
|
+
"if(a.role)Object.assign(vars,by.aws[a.role])}",
|
|
76
|
+
'if(spec.gcp){const c=spec.gcp;const tok=await idToken("gcp",c.audience);by.gcp={};',
|
|
77
|
+
'const sts=trim(c.stsEndpoint||"https://sts.googleapis.com"),iam=trim(c.iamEndpoint||"https://iamcredentials.googleapis.com");',
|
|
78
|
+
// #4912: stsEndpoint is Google's STS, or its full token URL (terragucci's `token_url`).
|
|
79
|
+
'const fed=json(await post(/\\/token$/.test(sts)?sts:sts+"/v1/token",{"content-type":"application/json"},JSON.stringify({grantType:"urn:ietf:params:oauth:grant-type:token-exchange",audience:"//iam.googleapis.com/"+c.provider,scope:"https://www.googleapis.com/auth/cloud-platform",requestedTokenType:"urn:ietf:params:oauth:token-type:access_token",subjectToken:tok,subjectTokenType:"urn:ietf:params:oauth:token-type:jwt"})),"Google STS").access_token;',
|
|
80
|
+
'if(!clean(fed))throw new Error("Google STS gave no token");',
|
|
81
|
+
'for(const sa of ids("gcp")){',
|
|
82
|
+
'const at=json(await post(iam+"/v1/projects/-/serviceAccounts/"+encodeURIComponent(sa)+":generateAccessToken",{"content-type":"application/json",authorization:"Bearer "+fed},JSON.stringify({scope:["https://www.googleapis.com/auth/cloud-platform"]})),"IAM credentials").accessToken;',
|
|
83
|
+
'if(!clean(at))throw new Error("IAM credentials gave no token for "+sa);',
|
|
84
|
+
"by.gcp[sa]={GOOGLE_OAUTH_ACCESS_TOKEN:at,CLOUDSDK_AUTH_ACCESS_TOKEN:at};secrets.push(at);said.push(sa)}",
|
|
85
|
+
"if(c.serviceAccount)Object.assign(vars,by.gcp[c.serviceAccount])}",
|
|
86
|
+
'if(spec.azure){const z=spec.azure;const tok=await idToken("azure",z.audience);by.azure={};',
|
|
87
|
+
'const host=trim(z.authority||"https://login.microsoftonline.com");',
|
|
88
|
+
'for(const cid of ids("azure")){',
|
|
89
|
+
'const at=json(await post(host+"/"+encodeURIComponent(z.tenantId)+"/oauth2/v2.0/token",{"content-type":"application/x-www-form-urlencoded"},new URLSearchParams({client_id:cid,scope:"https://management.azure.com/.default",grant_type:"client_credentials",client_assertion_type:"urn:ietf:params:oauth:client-assertion-type:jwt-bearer",client_assertion:tok}).toString()),"Entra").access_token;',
|
|
90
|
+
'if(!clean(at))throw new Error("Entra gave no token for "+cid);',
|
|
91
|
+
// #4572: with azure.database, a second grant for Azure Database for PostgreSQL's scope.
|
|
92
|
+
`let db;if(z.database){db=json(await post(host+"/"+encodeURIComponent(z.tenantId)+"/oauth2/v2.0/token",{"content-type":"application/x-www-form-urlencoded"},new URLSearchParams({client_id:cid,scope:${JSON.stringify(AZURE_DATABASE_SCOPE)},grant_type:"client_credentials",client_assertion_type:"urn:ietf:params:oauth:client-assertion-type:jwt-bearer",client_assertion:tok}).toString()),"Entra").access_token;if(!clean(db))throw new Error("Entra gave no database token for "+cid);secrets.push(db)}`,
|
|
93
|
+
`by.azure[cid]={AZURE_ACCESS_TOKEN:at,AZURE_CLIENT_ID:cid,AZURE_TENANT_ID:z.tenantId,ARM_CLIENT_ID:cid,ARM_TENANT_ID:z.tenantId,...(z.subscriptionId?{AZURE_SUBSCRIPTION_ID:z.subscriptionId,ARM_SUBSCRIPTION_ID:z.subscriptionId}:{}),...(db?{${AZURE_DATABASE_TOKEN_ENV}:db}:{})};secrets.push(at);said.push(cid)}`,
|
|
94
|
+
"if(z.clientId)Object.assign(vars,by.azure[z.clientId])}",
|
|
95
|
+
// #4549: Pulumi Cloud's OAuth token exchange, one access token per identity (pulumiTokenRequest).
|
|
96
|
+
'if(spec.pulumi){const p=spec.pulumi;const tok=await idToken("pulumi",p.audience);by.pulumi={};',
|
|
97
|
+
'const api=trim(p.apiUrl||"https://api.pulumi.com");',
|
|
98
|
+
'for(const id of ids("pulumi")){',
|
|
99
|
+
'const m=/^(team|user):([^\\s:]+)$/.exec(id),org=id==="organization"||id==="organization:admin";if(!m&&!org)throw new Error("Pulumi Cloud has no token for "+id);',
|
|
100
|
+
'const f={audience:"urn:pulumi:org:"+p.organization,grant_type:"urn:ietf:params:oauth:grant-type:token-exchange",subject_token_type:"urn:ietf:params:oauth:token-type:id_token",requested_token_type:"urn:pulumi:token-type:access_token:"+(m?(m[1]==="team"?"team":"personal"):"organization"),subject_token:tok};',
|
|
101
|
+
'if(m)f.scope=id;else if(id==="organization:admin")f.scope="admin";',
|
|
102
|
+
'const at=json(await post(api+"/api/oauth/token",{"content-type":"application/x-www-form-urlencoded",accept:"application/json"},new URLSearchParams(f).toString()),"Pulumi Cloud").access_token;',
|
|
103
|
+
'if(!clean(at))throw new Error("Pulumi Cloud gave no token for "+id);',
|
|
104
|
+
'by.pulumi[id]={PULUMI_ACCESS_TOKEN:at,...(p.apiUrl?{PULUMI_BACKEND_URL:api}:{})};secrets.push(at);said.push("Pulumi Cloud "+id)}',
|
|
105
|
+
"if(p.token)Object.assign(vars,by.pulumi[p.token])}",
|
|
106
|
+
// #4332: with targets, every identity's variables go in a file of their own, outside the checkout.
|
|
107
|
+
"const clouds=Object.keys(by);if(clouds.some((c)=>(spec[c].targets||[]).length>0)){",
|
|
108
|
+
"const doc={version:1,clouds:{}};for(const c of clouds){const s=spec[c];doc.clouds[c]={...(s[KEY[c]]?{default:s[KEY[c]]}:{}),targets:(s.targets||[]).map((t)=>({targets:t.targets,identity:t[KEY[c]]})),vars:by[c]}}",
|
|
109
|
+
'const tf=trim(process.env.RUNNER_TEMP||process.env.TMPDIR||"/tmp")+"/chant-cloud-targets-"+require("crypto").randomBytes(8).toString("hex")+".json";',
|
|
110
|
+
`fs.writeFileSync(tf,JSON.stringify(doc),{mode:0o600,flag:"wx"});vars.${CLOUD_TARGETS_ENV}=tf}`,
|
|
111
|
+
// #4930: which clouds this job traded, so a product tells the trade's targets file from a login's.
|
|
112
|
+
`if(clouds.length)vars.${CLOUD_TRADED_ENV}=clouds.join(",");`,
|
|
113
|
+
'for(const [k,v] of Object.entries(vars))if(!clean(v))throw new Error(k+" is not a value the job can hold");',
|
|
114
|
+
'if(format==="github-env"){for(const s of secrets)console.log("::add-mask::"+s);fs.appendFileSync(out,Object.entries(vars).map(([k,v])=>k+"="+v+"\\n").join(""))}',
|
|
115
|
+
'else{const sh=Object.entries(vars).map(([k,v])=>"export "+k+"="+Q+v.split(Q).join(Q+"\\\\"+Q+Q)+Q+"\\n").join("");if(out==="-")process.stdout.write(sh);else fs.writeFileSync(out,sh,{mode:0o600})}',
|
|
116
|
+
'for(const s of said)console.error("chant: traded the job\\u0027s OIDC token for "+s)};',
|
|
117
|
+
"run().catch((e)=>fail(e&&e.message?e.message:String(e)));"
|
|
118
|
+
].join("");
|
|
119
|
+
function readTargetsFile(path, read = (p) => readFileSync(p, "utf-8")) {
|
|
120
|
+
let file;
|
|
121
|
+
try {
|
|
122
|
+
file = JSON.parse(read(path));
|
|
123
|
+
} catch (err) {
|
|
124
|
+
throw new Error(`${CLOUD_TARGETS_ENV} names ${path}, which cannot be read as the trade's targets file: ${err instanceof Error ? err.message : String(err)}`);
|
|
125
|
+
}
|
|
126
|
+
if (!file || file.version !== 1 || typeof file.clouds !== "object" || file.clouds === null)
|
|
127
|
+
throw new Error(`${CLOUD_TARGETS_ENV} names ${path}, which is not a version 1 targets file`);
|
|
128
|
+
return file;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export {
|
|
132
|
+
IDENTITY_CLOUDS,
|
|
133
|
+
cloudIdentityProblems,
|
|
134
|
+
CLOUD_TARGETS_ENV,
|
|
135
|
+
readTargetsFile
|
|
136
|
+
};
|