@firestartr/cli 2.10.0-snapshot-org-secrets-ref-fix-1 → 2.10.0-snapshot-org-secrets-fix-1
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/build/index.js +297 -37
- package/build/packages/cdk8s_renderer/imports/firestartr.dev.d.ts +0 -34
- package/build/packages/gh_provisioner/src/entities/ghorgsecretsection/index.d.ts +7 -0
- package/build/packages/gh_provisioner/src/entities/ghorgsecretsection/secrets.d.ts +16 -0
- package/build/packages/github/index.d.ts +7 -1
- package/build/packages/github/src/orgSecrets.d.ts +10 -0
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -280314,7 +280314,7 @@ function getCronNextInterval(cronLine, tz) {
|
|
|
280314
280314
|
|
|
280315
280315
|
/***/ }),
|
|
280316
280316
|
|
|
280317
|
-
/***/
|
|
280317
|
+
/***/ 3342:
|
|
280318
280318
|
/***/ ((__unused_webpack_module, __webpack_exports__, __nccwpck_require__) => {
|
|
280319
280319
|
|
|
280320
280320
|
// ESM COMPAT FLAG
|
|
@@ -285979,6 +285979,66 @@ async function encryptRepoSecret(owner, repo, section, plaintextValue, octokit)
|
|
|
285979
285979
|
}
|
|
285980
285980
|
}
|
|
285981
285981
|
|
|
285982
|
+
;// CONCATENATED MODULE: ../github/src/orgSecrets.ts
|
|
285983
|
+
|
|
285984
|
+
|
|
285985
|
+
|
|
285986
|
+
async function getOrgPublicKey(org, section, octokit) {
|
|
285987
|
+
logger.info(`Retrieving org public key for ${org} (${section})`);
|
|
285988
|
+
try {
|
|
285989
|
+
if (!octokit) {
|
|
285990
|
+
octokit = await getOctokitForOrg(org);
|
|
285991
|
+
}
|
|
285992
|
+
const { data } = await octokit.rest[`${section}`].getOrgPublicKey({
|
|
285993
|
+
org,
|
|
285994
|
+
});
|
|
285995
|
+
return data;
|
|
285996
|
+
}
|
|
285997
|
+
catch (error) {
|
|
285998
|
+
logger.error(`Error retrieving org public key (${section}) for ${org}: ${error}`);
|
|
285999
|
+
throw error;
|
|
286000
|
+
}
|
|
286001
|
+
}
|
|
286002
|
+
async function encryptOrgSecret(org, section, plaintextValue, preFetchedKey, octokit) {
|
|
286003
|
+
try {
|
|
286004
|
+
const { key_id, key } = preFetchedKey
|
|
286005
|
+
? preFetchedKey
|
|
286006
|
+
: await getOrgPublicKey(org, section, octokit);
|
|
286007
|
+
await libsodium_wrappers.ready;
|
|
286008
|
+
const publicKey = libsodium_wrappers.from_base64(key, libsodium_wrappers.base64_variants.ORIGINAL);
|
|
286009
|
+
const secretBytes = libsodium_wrappers.from_string(plaintextValue);
|
|
286010
|
+
const encryptedBytes = libsodium_wrappers.crypto_box_seal(secretBytes, publicKey);
|
|
286011
|
+
const encryptedValue = libsodium_wrappers.to_base64(encryptedBytes, libsodium_wrappers.base64_variants.ORIGINAL);
|
|
286012
|
+
return {
|
|
286013
|
+
key_id,
|
|
286014
|
+
encrypted_value: encryptedValue,
|
|
286015
|
+
};
|
|
286016
|
+
}
|
|
286017
|
+
catch (err) {
|
|
286018
|
+
logger.error(`Error encrypting org secret (${section}) for ${org}: ${err}`);
|
|
286019
|
+
throw err;
|
|
286020
|
+
}
|
|
286021
|
+
}
|
|
286022
|
+
async function getOrgSecret(org, section, name, octokit) {
|
|
286023
|
+
logger.info(`Checking org secret ${name} (${section}) for ${org}`);
|
|
286024
|
+
try {
|
|
286025
|
+
if (!octokit) {
|
|
286026
|
+
octokit = await getOctokitForOrg(org);
|
|
286027
|
+
}
|
|
286028
|
+
const response = await octokit.rest[`${section}`].getOrgSecret({
|
|
286029
|
+
org,
|
|
286030
|
+
secret_name: name,
|
|
286031
|
+
});
|
|
286032
|
+
return response.data;
|
|
286033
|
+
}
|
|
286034
|
+
catch (err) {
|
|
286035
|
+
if (err && err.status === 404) {
|
|
286036
|
+
return null;
|
|
286037
|
+
}
|
|
286038
|
+
throw err;
|
|
286039
|
+
}
|
|
286040
|
+
}
|
|
286041
|
+
|
|
285982
286042
|
;// CONCATENATED MODULE: ../github/src/profile.ts
|
|
285983
286043
|
// Profile definitions and store for github package (immutable and ambient profiles)
|
|
285984
286044
|
const profileStore = new Map();
|
|
@@ -286412,6 +286472,7 @@ function withProfile(profileName) {
|
|
|
286412
286472
|
|
|
286413
286473
|
|
|
286414
286474
|
|
|
286475
|
+
|
|
286415
286476
|
/* harmony default export */ const github = ({
|
|
286416
286477
|
org: organization,
|
|
286417
286478
|
repo: repository,
|
|
@@ -286434,6 +286495,9 @@ function withProfile(profileName) {
|
|
|
286434
286495
|
encryption: {
|
|
286435
286496
|
encryptRepoSecret: encryptRepoSecret,
|
|
286436
286497
|
getRepoPublicKey: getRepoPublicKey,
|
|
286498
|
+
getOrgPublicKey: getOrgPublicKey,
|
|
286499
|
+
encryptOrgSecret: encryptOrgSecret,
|
|
286500
|
+
getOrgSecret: getOrgSecret,
|
|
286437
286501
|
},
|
|
286438
286502
|
withProfile: withProfile,
|
|
286439
286503
|
createProfile: createProfile,
|
|
@@ -319334,8 +319398,8 @@ var dist = __nccwpck_require__(44516);
|
|
|
319334
319398
|
var dist_default = /*#__PURE__*/__nccwpck_require__.n(dist);
|
|
319335
319399
|
// EXTERNAL MODULE: ../catalog_common/index.ts + 44 modules
|
|
319336
319400
|
var catalog_common = __nccwpck_require__(78542);
|
|
319337
|
-
// EXTERNAL MODULE: ../github/index.ts +
|
|
319338
|
-
var github = __nccwpck_require__(
|
|
319401
|
+
// EXTERNAL MODULE: ../github/index.ts + 38 modules
|
|
319402
|
+
var github = __nccwpck_require__(3342);
|
|
319339
319403
|
;// CONCATENATED MODULE: ../cdk8s_renderer/src/patches/base.ts
|
|
319340
319404
|
class BasePatches {
|
|
319341
319405
|
constructor() { }
|
|
@@ -327587,7 +327651,6 @@ function toJson_FirestartrGithubOrganizationSecretSectionSpec(obj) {
|
|
|
327587
327651
|
'secrets': toJson_FirestartrGithubOrganizationSecretSectionSpecSecrets(obj.secrets),
|
|
327588
327652
|
'context': toJson_FirestartrGithubOrganizationSecretSectionSpecContext(obj.context),
|
|
327589
327653
|
'firestartr': toJson_FirestartrGithubOrganizationSecretSectionSpecFirestartr(obj.firestartr),
|
|
327590
|
-
'writeConnectionSecretToRef': toJson_FirestartrGithubOrganizationSecretSectionSpecWriteConnectionSecretToRef(obj.writeConnectionSecretToRef),
|
|
327591
327654
|
};
|
|
327592
327655
|
// filter undefined values
|
|
327593
327656
|
return Object.entries(result).reduce((r, i) => (i[1] === undefined) ? r : ({ ...r, [i[0]]: i[1] }), {});
|
|
@@ -327637,21 +327700,6 @@ function toJson_FirestartrGithubOrganizationSecretSectionSpecFirestartr(obj) {
|
|
|
327637
327700
|
// filter undefined values
|
|
327638
327701
|
return Object.entries(result).reduce((r, i) => (i[1] === undefined) ? r : ({ ...r, [i[0]]: i[1] }), {});
|
|
327639
327702
|
}
|
|
327640
|
-
/**
|
|
327641
|
-
* Converts an object of type 'FirestartrGithubOrganizationSecretSectionSpecWriteConnectionSecretToRef' to JSON representation.
|
|
327642
|
-
*/
|
|
327643
|
-
/* eslint-disable max-len, @stylistic/max-len, quote-props, @stylistic/quote-props */
|
|
327644
|
-
function toJson_FirestartrGithubOrganizationSecretSectionSpecWriteConnectionSecretToRef(obj) {
|
|
327645
|
-
if (obj === undefined) {
|
|
327646
|
-
return undefined;
|
|
327647
|
-
}
|
|
327648
|
-
const result = {
|
|
327649
|
-
'name': obj.name,
|
|
327650
|
-
'outputs': obj.outputs?.map(y => toJson_FirestartrGithubOrganizationSecretSectionSpecWriteConnectionSecretToRefOutputs(y)),
|
|
327651
|
-
};
|
|
327652
|
-
// filter undefined values
|
|
327653
|
-
return Object.entries(result).reduce((r, i) => (i[1] === undefined) ? r : ({ ...r, [i[0]]: i[1] }), {});
|
|
327654
|
-
}
|
|
327655
327703
|
/**
|
|
327656
327704
|
* Converts an object of type 'FirestartrGithubOrganizationSecretSectionSpecSecretsActions' to JSON representation.
|
|
327657
327705
|
*/
|
|
@@ -327731,20 +327779,6 @@ function toJson_FirestartrGithubOrganizationSecretSectionSpecContextProvider(obj
|
|
|
327731
327779
|
// filter undefined values
|
|
327732
327780
|
return Object.entries(result).reduce((r, i) => (i[1] === undefined) ? r : ({ ...r, [i[0]]: i[1] }), {});
|
|
327733
327781
|
}
|
|
327734
|
-
/**
|
|
327735
|
-
* Converts an object of type 'FirestartrGithubOrganizationSecretSectionSpecWriteConnectionSecretToRefOutputs' to JSON representation.
|
|
327736
|
-
*/
|
|
327737
|
-
/* eslint-disable max-len, @stylistic/max-len, quote-props, @stylistic/quote-props */
|
|
327738
|
-
function toJson_FirestartrGithubOrganizationSecretSectionSpecWriteConnectionSecretToRefOutputs(obj) {
|
|
327739
|
-
if (obj === undefined) {
|
|
327740
|
-
return undefined;
|
|
327741
|
-
}
|
|
327742
|
-
const result = {
|
|
327743
|
-
'key': obj.key,
|
|
327744
|
-
};
|
|
327745
|
-
// filter undefined values
|
|
327746
|
-
return Object.entries(result).reduce((r, i) => (i[1] === undefined) ? r : ({ ...r, [i[0]]: i[1] }), {});
|
|
327747
|
-
}
|
|
327748
327782
|
/**
|
|
327749
327783
|
* Converts an object of type 'FirestartrGithubOrganizationSecretSectionSpecSecretsActionsRef' to JSON representation.
|
|
327750
327784
|
*/
|
|
@@ -331332,6 +331366,7 @@ class GithubOrgVariableSectionChart extends BaseGithubChart {
|
|
|
331332
331366
|
;// CONCATENATED MODULE: ../cdk8s_renderer/src/charts/github/orgSecretSectionChart.ts
|
|
331333
331367
|
|
|
331334
331368
|
|
|
331369
|
+
|
|
331335
331370
|
class GithubOrgSecretSectionChart extends BaseGithubChart {
|
|
331336
331371
|
template() {
|
|
331337
331372
|
const claim = this.get('claim');
|
|
@@ -331344,6 +331379,20 @@ class GithubOrgSecretSectionChart extends BaseGithubChart {
|
|
|
331344
331379
|
return [];
|
|
331345
331380
|
return secrets.map((secret) => {
|
|
331346
331381
|
const parts = secret.value.split(':');
|
|
331382
|
+
const selectedRepositories = (secret.selected_repositories || []).map((ref) => {
|
|
331383
|
+
const match = ref.match(/^component:(.+)$/);
|
|
331384
|
+
if (!match) {
|
|
331385
|
+
throw new ChartRenderError('OrgSettingsClaim', claim.name, `Invalid component ref "${ref}" in selected_repositories. Expected format: component:<name>`);
|
|
331386
|
+
}
|
|
331387
|
+
const componentName = match[1];
|
|
331388
|
+
const resolvedCr = this.refResolver('ComponentClaim', componentName);
|
|
331389
|
+
const org = resolvedCr?.spec?.org;
|
|
331390
|
+
const repoName = resolvedCr?.metadata?.annotations?.['firestartr.dev/external-name'] || resolvedCr?.metadata?.name?.replace(/-[0-9a-f-]{36}$/, '');
|
|
331391
|
+
if (!org || !repoName) {
|
|
331392
|
+
throw new ChartRenderError('OrgSettingsClaim', claim.name, `Referenced component "${componentName}" has no GitHub provider configured`);
|
|
331393
|
+
}
|
|
331394
|
+
return `${org}/${repoName}`;
|
|
331395
|
+
});
|
|
331347
331396
|
return {
|
|
331348
331397
|
name: secret.name,
|
|
331349
331398
|
ref: {
|
|
@@ -331352,7 +331401,7 @@ class GithubOrgSecretSectionChart extends BaseGithubChart {
|
|
|
331352
331401
|
key: parts[3],
|
|
331353
331402
|
},
|
|
331354
331403
|
visibility: secret.visibility || 'all',
|
|
331355
|
-
selectedRepositories
|
|
331404
|
+
selectedRepositories,
|
|
331356
331405
|
};
|
|
331357
331406
|
});
|
|
331358
331407
|
};
|
|
@@ -331371,7 +331420,7 @@ class GithubOrgSecretSectionChart extends BaseGithubChart {
|
|
|
331371
331420
|
tfStateKey: firestartrId ? `${firestartrId}-secrets` : firestartrId,
|
|
331372
331421
|
},
|
|
331373
331422
|
writeConnectionSecretToRef: {
|
|
331374
|
-
name: `firestartrgithuborganizationsecretsection-${githubProvider.name}-outputs`.toLowerCase(),
|
|
331423
|
+
name: `firestartrgithuborganizationsecretsection-${githubProvider.name}-secrets-outputs`.toLowerCase(),
|
|
331375
331424
|
outputs: [{ key: 'managed_secrets' }, { key: 'secret_ids' }],
|
|
331376
331425
|
},
|
|
331377
331426
|
},
|
|
@@ -335189,6 +335238,7 @@ const kindPluralMap = {
|
|
|
335189
335238
|
githuborgwebhooks: 'FirestartrGithubOrgWebhook',
|
|
335190
335239
|
githuborganizationsettings: 'FirestartrGithubOrganizationSettings',
|
|
335191
335240
|
githuborganizationvariablesections: 'FirestartrGithubOrganizationVariableSection',
|
|
335241
|
+
githuborganizationsecretsections: 'FirestartrGithubOrganizationSecretSection',
|
|
335192
335242
|
terraformworkspaces: 'FirestartrTerraformWorkspace',
|
|
335193
335243
|
terraformworkspaceplans: 'FirestartrTerraformWorkspacePlan',
|
|
335194
335244
|
providerconfigs: 'FirestartrProviderConfig',
|
|
@@ -337167,6 +337217,7 @@ const kindsWithFinalizer = [
|
|
|
337167
337217
|
'FirestartrGithubOrgWebhook',
|
|
337168
337218
|
'FirestartrGithubOrganizationSettings',
|
|
337169
337219
|
'FirestartrGithubOrganizationVariableSection',
|
|
337220
|
+
'FirestartrGithubOrganizationSecretSection',
|
|
337170
337221
|
'FirestartrGithubRepositorySecretsSection',
|
|
337171
337222
|
];
|
|
337172
337223
|
const kindsWithDependants = [
|
|
@@ -340116,7 +340167,7 @@ async function configGit() {
|
|
|
340116
340167
|
}
|
|
340117
340168
|
// Import github dynamically to avoid Jest ESM issues when not specifically running this function
|
|
340118
340169
|
// (see CONSTITUTION and RULES: must not change test machinery)
|
|
340119
|
-
const githubModule = await Promise.resolve(/* import() */).then(__nccwpck_require__.bind(__nccwpck_require__,
|
|
340170
|
+
const githubModule = await Promise.resolve(/* import() */).then(__nccwpck_require__.bind(__nccwpck_require__, 3342));
|
|
340120
340171
|
const github = githubModule.default || githubModule;
|
|
340121
340172
|
if (external_fs_.existsSync(gitconfigPath)) {
|
|
340122
340173
|
external_fs_.rmSync(gitconfigPath);
|
|
@@ -343712,6 +343763,11 @@ const MODULES = {
|
|
|
343712
343763
|
module: 'git::https://github.com/prefapp/tfm.git//modules/github-org-variables-section',
|
|
343713
343764
|
ref: '79c1407',
|
|
343714
343765
|
},
|
|
343766
|
+
FirestartrGithubOrganizationSecretSection: {
|
|
343767
|
+
module: 'git::https://github.com/prefapp/tfm.git//modules/github-org-secrets-section',
|
|
343768
|
+
// feat/1364-feat-add-github-org-secrets-section-module
|
|
343769
|
+
ref: '4380434b158bb38d0b831b0f3d1fc51e7bd509a4',
|
|
343770
|
+
},
|
|
343715
343771
|
};
|
|
343716
343772
|
function getFirestartrDefaultTFM(kind) {
|
|
343717
343773
|
if (kind in MODULES) {
|
|
@@ -345602,6 +345658,206 @@ class EntityGHOrgVarsSection extends base_Entity {
|
|
|
345602
345658
|
async loadAddressesToImport() { }
|
|
345603
345659
|
}
|
|
345604
345660
|
|
|
345661
|
+
;// CONCATENATED MODULE: ../gh_provisioner/src/entities/ghorgsecretsection/secrets.ts
|
|
345662
|
+
|
|
345663
|
+
|
|
345664
|
+
|
|
345665
|
+
|
|
345666
|
+
const secrets_SECTIONS = ['actions', 'codespaces', 'dependabot'];
|
|
345667
|
+
|
|
345668
|
+
async function provisionOrgSecrets(entity, secrets) {
|
|
345669
|
+
gh_provisioner_src_logger.info(`[gh-provisioner] ${entity.k8sId} provisioning org secrets`);
|
|
345670
|
+
for (const section of secrets_SECTIONS) {
|
|
345671
|
+
const sectionSecrets = secrets[section] || [];
|
|
345672
|
+
if (sectionSecrets.length === 0)
|
|
345673
|
+
continue;
|
|
345674
|
+
let preFetchedKey;
|
|
345675
|
+
try {
|
|
345676
|
+
preFetchedKey = await fetchOrgPublicKey(entity, section);
|
|
345677
|
+
}
|
|
345678
|
+
catch (err) {
|
|
345679
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
345680
|
+
throw new Error(`[gh-provisioner] ${entity.k8sId} failed to fetch ${section} org public key: ${message}`);
|
|
345681
|
+
}
|
|
345682
|
+
for (const secret of sectionSecrets) {
|
|
345683
|
+
await provisionOrgSecret(entity, section, secret, preFetchedKey);
|
|
345684
|
+
}
|
|
345685
|
+
}
|
|
345686
|
+
}
|
|
345687
|
+
async function fetchOrgPublicKey(entity, section) {
|
|
345688
|
+
return (await entity.runWithGithubProvider(async () => {
|
|
345689
|
+
return await github["default"].encryption.getOrgPublicKey(entity.cr.spec.org, section);
|
|
345690
|
+
}));
|
|
345691
|
+
}
|
|
345692
|
+
async function provisionOrgSecret(entity, section, secret, preFetchedKey) {
|
|
345693
|
+
gh_provisioner_src_logger.info(`[gh-provisioner] provisioning org secret ${entity.k8sId}/${section}/${secret.name}`);
|
|
345694
|
+
if (process.env['AVOID_PROVIDER_SECRET_ENCRYPTION']) {
|
|
345695
|
+
await secrets_createUnencryptedSecret(entity, section, secret);
|
|
345696
|
+
}
|
|
345697
|
+
else {
|
|
345698
|
+
await secrets_createEncryptedSecret(entity, section, secret, preFetchedKey);
|
|
345699
|
+
}
|
|
345700
|
+
gh_provisioner_src_logger.info(`[gh-provisioner] org secret provisioned ${section}/${secret.name}`);
|
|
345701
|
+
}
|
|
345702
|
+
async function secrets_createEncryptedSecret(entity, section, secret, preFetchedKey) {
|
|
345703
|
+
const plainSecret = base_Entity.refResolver(secret.ref);
|
|
345704
|
+
const plainTextSecret = plainSecret.getOutput(secret.ref.key);
|
|
345705
|
+
const plaintextSha256 = external_crypto_default().createHash('sha256')
|
|
345706
|
+
.update(plainTextSecret)
|
|
345707
|
+
.digest('hex');
|
|
345708
|
+
const { encrypted_value } = (await entity.runWithGithubProvider(async () => {
|
|
345709
|
+
return await github["default"].encryption.encryptOrgSecret(entity.cr.spec.org, section, plainTextSecret, preFetchedKey);
|
|
345710
|
+
}));
|
|
345711
|
+
entity.patchData({
|
|
345712
|
+
op: PatchOperations.add,
|
|
345713
|
+
path: `/config/${section}/${secret.name}`,
|
|
345714
|
+
value: {
|
|
345715
|
+
value: encrypted_value,
|
|
345716
|
+
visibility: secret.visibility || 'all',
|
|
345717
|
+
...(secret.selectedRepositories && secret.selectedRepositories.length > 0
|
|
345718
|
+
? { selectedRepositories: secret.selectedRepositories }
|
|
345719
|
+
: {}),
|
|
345720
|
+
},
|
|
345721
|
+
});
|
|
345722
|
+
entity.patchData({
|
|
345723
|
+
op: PatchOperations.add,
|
|
345724
|
+
path: `/config/${section}_sha256/${secret.name}`,
|
|
345725
|
+
value: plaintextSha256,
|
|
345726
|
+
});
|
|
345727
|
+
}
|
|
345728
|
+
async function secrets_createUnencryptedSecret(entity, section, secret) {
|
|
345729
|
+
const plainSecret = base_Entity.refResolver(secret.ref);
|
|
345730
|
+
const plainTextSecret = plainSecret.getOutput(secret.ref.key);
|
|
345731
|
+
const plaintextSha256 = external_crypto_default().createHash('sha256')
|
|
345732
|
+
.update(plainTextSecret)
|
|
345733
|
+
.digest('hex');
|
|
345734
|
+
entity.patchData({
|
|
345735
|
+
op: PatchOperations.add,
|
|
345736
|
+
path: `/config/${section}/${secret.name}`,
|
|
345737
|
+
value: {
|
|
345738
|
+
value: plainTextSecret,
|
|
345739
|
+
visibility: secret.visibility || 'all',
|
|
345740
|
+
...(secret.selectedRepositories && secret.selectedRepositories.length > 0
|
|
345741
|
+
? { selectedRepositories: secret.selectedRepositories }
|
|
345742
|
+
: {}),
|
|
345743
|
+
},
|
|
345744
|
+
});
|
|
345745
|
+
entity.patchData({
|
|
345746
|
+
op: PatchOperations.add,
|
|
345747
|
+
path: `/config/${section}_sha256/${secret.name}`,
|
|
345748
|
+
value: plaintextSha256,
|
|
345749
|
+
});
|
|
345750
|
+
}
|
|
345751
|
+
async function adoptSecretsIfNeeded(entity, secrets) {
|
|
345752
|
+
const managedSecrets = entity.cr.fResolveSelfOutputs('managed_secrets') || [];
|
|
345753
|
+
for (const section of secrets_SECTIONS) {
|
|
345754
|
+
const sectionSecrets = secrets[section] || [];
|
|
345755
|
+
if (sectionSecrets.length === 0)
|
|
345756
|
+
continue;
|
|
345757
|
+
const declaredNames = sectionSecrets.map((s) => s.name);
|
|
345758
|
+
const newToModule = declaredNames.filter((name) => !managedSecrets.includes(name));
|
|
345759
|
+
if (newToModule.length === 0) {
|
|
345760
|
+
gh_provisioner_src_logger.debug(`[gh-provisioner] ${entity.k8sId} all declared ${section} secrets are already managed`);
|
|
345761
|
+
continue;
|
|
345762
|
+
}
|
|
345763
|
+
if (managedSecrets.length === 0) {
|
|
345764
|
+
gh_provisioner_src_logger.info(`[gh-provisioner] ${entity.k8sId} no managed_secrets output — first reconciliation, treating all ${newToModule.length} ${section} secret(s) as new to module`);
|
|
345765
|
+
}
|
|
345766
|
+
for (const secretName of newToModule) {
|
|
345767
|
+
try {
|
|
345768
|
+
const existing = (await entity.runWithGithubProvider(async () => {
|
|
345769
|
+
return await github["default"].encryption.getOrgSecret(entity.cr.spec.org, section, secretName);
|
|
345770
|
+
}));
|
|
345771
|
+
if (existing) {
|
|
345772
|
+
gh_provisioner_src_logger.info(`[gh-provisioner] ${entity.k8sId} adopting pre-existing ${section} secret '${secretName}' on GitHub org '${entity.cr.spec.org}'`);
|
|
345773
|
+
const resourceType = `github_${section}_organization_secret`;
|
|
345774
|
+
entity.patchImportData({
|
|
345775
|
+
op: PatchOperations.add,
|
|
345776
|
+
path: '/imports/-',
|
|
345777
|
+
value: {
|
|
345778
|
+
to: `${resourceType}.this["${secretName}"]`,
|
|
345779
|
+
id: secretName,
|
|
345780
|
+
},
|
|
345781
|
+
});
|
|
345782
|
+
const secretEntry = sectionSecrets.find((s) => s.name === secretName);
|
|
345783
|
+
if (secretEntry &&
|
|
345784
|
+
secretEntry.visibility === 'selected' &&
|
|
345785
|
+
(section === 'actions' || section === 'dependabot')) {
|
|
345786
|
+
const bindingType = `github_${section}_organization_secret_repositories`;
|
|
345787
|
+
entity.patchImportData({
|
|
345788
|
+
op: PatchOperations.add,
|
|
345789
|
+
path: '/imports/-',
|
|
345790
|
+
value: {
|
|
345791
|
+
to: `${bindingType}.this["${secretName}"]`,
|
|
345792
|
+
id: secretName,
|
|
345793
|
+
},
|
|
345794
|
+
});
|
|
345795
|
+
}
|
|
345796
|
+
}
|
|
345797
|
+
}
|
|
345798
|
+
catch (err) {
|
|
345799
|
+
if (err && err.status === 404) {
|
|
345800
|
+
gh_provisioner_src_logger.info(`[gh-provisioner] ${entity.k8sId} ${section} secret '${secretName}' not found on GitHub org '${entity.cr.spec.org}' — will be created by TFM`);
|
|
345801
|
+
}
|
|
345802
|
+
else if (err && (err.status === 401 || err.status === 403)) {
|
|
345803
|
+
gh_provisioner_src_logger.warn(`[gh-provisioner] ${entity.k8sId} token lacks scope to check ${section} secret '${secretName}' on org '${entity.cr.spec.org}' — skipping adoption gracefully`);
|
|
345804
|
+
}
|
|
345805
|
+
else {
|
|
345806
|
+
gh_provisioner_src_logger.warn(`[gh-provisioner] ${entity.k8sId} unexpected error checking ${section} secret '${secretName}' on org '${entity.cr.spec.org}': ${err instanceof Error ? err.message : String(err)}`);
|
|
345807
|
+
}
|
|
345808
|
+
}
|
|
345809
|
+
}
|
|
345810
|
+
}
|
|
345811
|
+
}
|
|
345812
|
+
|
|
345813
|
+
;// CONCATENATED MODULE: ../gh_provisioner/src/entities/ghorgsecretsection/index.ts
|
|
345814
|
+
|
|
345815
|
+
|
|
345816
|
+
|
|
345817
|
+
class EntityGHOrgSecretSection extends base_Entity {
|
|
345818
|
+
constructor(artifact) {
|
|
345819
|
+
super(artifact, {
|
|
345820
|
+
config: {
|
|
345821
|
+
org: '',
|
|
345822
|
+
actions: {},
|
|
345823
|
+
codespaces: {},
|
|
345824
|
+
dependabot: {},
|
|
345825
|
+
actions_sha256: {},
|
|
345826
|
+
codespaces_sha256: {},
|
|
345827
|
+
dependabot_sha256: {},
|
|
345828
|
+
},
|
|
345829
|
+
});
|
|
345830
|
+
}
|
|
345831
|
+
async loadResources(tfOp) {
|
|
345832
|
+
gh_provisioner_src_logger.info(`[gh-provisioner] running ${tfOp} on ${this.k8sId}`);
|
|
345833
|
+
try {
|
|
345834
|
+
const cr = this.cr;
|
|
345835
|
+
const org = cr.spec.org;
|
|
345836
|
+
const secrets = cr.spec.secrets || {};
|
|
345837
|
+
this.patchData({
|
|
345838
|
+
op: PatchOperations.replace,
|
|
345839
|
+
path: '/config/org',
|
|
345840
|
+
value: org,
|
|
345841
|
+
});
|
|
345842
|
+
await provisionOrgSecrets(this, secrets);
|
|
345843
|
+
const redactedDoc = JSON.parse(JSON.stringify(this._document, (key, value) => typeof value === 'string' && value.length > 50 ? '[REDACTED]' : value));
|
|
345844
|
+
this.synthMessage(`[gh-provisioner] ${this.k8sId} config:\n${JSON.stringify(redactedDoc, null, 2)}`);
|
|
345845
|
+
this.synthEnd(`[gh-provisioner] ${this.k8sId} loaded its data`);
|
|
345846
|
+
if (tfOp === 'apply') {
|
|
345847
|
+
await adoptSecretsIfNeeded(this, secrets);
|
|
345848
|
+
}
|
|
345849
|
+
gh_provisioner_src_logger.debug(`[gh-provisioner] ${this.k8sId} loaded its data`);
|
|
345850
|
+
}
|
|
345851
|
+
catch (err) {
|
|
345852
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
345853
|
+
gh_provisioner_src_logger.error(`[gh-provisioner] ${this.k8sId} error loading resources: ${message}`);
|
|
345854
|
+
throw new Error(`[gh-provisioner] ${this.k8sId} error loading resources: ${message}`);
|
|
345855
|
+
}
|
|
345856
|
+
}
|
|
345857
|
+
async postProvision(_tfOp) { }
|
|
345858
|
+
async loadAddressesToImport() { }
|
|
345859
|
+
}
|
|
345860
|
+
|
|
345605
345861
|
;// CONCATENATED MODULE: ../gh_provisioner/src/entities/ghorgwebhook/index.ts
|
|
345606
345862
|
|
|
345607
345863
|
|
|
@@ -345679,6 +345935,7 @@ class EntityGHOrgWebHook extends base_Entity {
|
|
|
345679
345935
|
|
|
345680
345936
|
|
|
345681
345937
|
|
|
345938
|
+
|
|
345682
345939
|
function entities_getEntity(cr) {
|
|
345683
345940
|
const entityClass = getEntityClass(cr.kind);
|
|
345684
345941
|
return new entityClass(cr);
|
|
@@ -345701,6 +345958,8 @@ function getEntityClass(kind) {
|
|
|
345701
345958
|
return EntityGHOrgSettings;
|
|
345702
345959
|
case 'FirestartrGithubOrganizationVariableSection':
|
|
345703
345960
|
return EntityGHOrgVarsSection;
|
|
345961
|
+
case 'FirestartrGithubOrganizationSecretSection':
|
|
345962
|
+
return EntityGHOrgSecretSection;
|
|
345704
345963
|
default:
|
|
345705
345964
|
throw new Error(`kind ${kind} has no entity associated`);
|
|
345706
345965
|
}
|
|
@@ -347450,6 +347709,7 @@ const provisionImplementations = {
|
|
|
347450
347709
|
githuborgwebhooks: process_operation_processOperation,
|
|
347451
347710
|
githuborganizationsettings: process_operation_processOperation,
|
|
347452
347711
|
githuborganizationvariablesections: process_operation_processOperation,
|
|
347712
|
+
githuborganizationsecretsections: process_operation_processOperation,
|
|
347453
347713
|
fsdummiesa: processFirestartrDummies,
|
|
347454
347714
|
fsdummiesb: processFirestartrDummies,
|
|
347455
347715
|
fsdummiesc: processFirestartrDummies,
|
|
@@ -526268,7 +526528,7 @@ const crsStatusSubcommand = {
|
|
|
526268
526528
|
};
|
|
526269
526529
|
|
|
526270
526530
|
;// CONCATENATED MODULE: ./package.json
|
|
526271
|
-
const package_namespaceObject = JSON.parse('{"i8":"2.10.0-snapshot-org-secrets-
|
|
526531
|
+
const package_namespaceObject = JSON.parse('{"i8":"2.10.0-snapshot-org-secrets-fix-1"}');
|
|
526272
526532
|
;// CONCATENATED MODULE: ../../package.json
|
|
526273
526533
|
const package_namespaceObject_1 = {"i8":"2.9.0"};
|
|
526274
526534
|
// EXTERNAL MODULE: ../../node_modules/semver/index.js
|
|
@@ -595,10 +595,6 @@ export interface FirestartrGithubOrganizationSecretSectionSpec {
|
|
|
595
595
|
* @schema FirestartrGithubOrganizationSecretSectionSpec#firestartr
|
|
596
596
|
*/
|
|
597
597
|
readonly firestartr: FirestartrGithubOrganizationSecretSectionSpecFirestartr;
|
|
598
|
-
/**
|
|
599
|
-
* @schema FirestartrGithubOrganizationSecretSectionSpec#writeConnectionSecretToRef
|
|
600
|
-
*/
|
|
601
|
-
readonly writeConnectionSecretToRef: FirestartrGithubOrganizationSecretSectionSpecWriteConnectionSecretToRef;
|
|
602
598
|
}
|
|
603
599
|
/**
|
|
604
600
|
* Converts an object of type 'FirestartrGithubOrganizationSecretSectionSpec' to JSON representation.
|
|
@@ -657,23 +653,6 @@ export interface FirestartrGithubOrganizationSecretSectionSpecFirestartr {
|
|
|
657
653
|
* Converts an object of type 'FirestartrGithubOrganizationSecretSectionSpecFirestartr' to JSON representation.
|
|
658
654
|
*/
|
|
659
655
|
export declare function toJson_FirestartrGithubOrganizationSecretSectionSpecFirestartr(obj: FirestartrGithubOrganizationSecretSectionSpecFirestartr | undefined): Record<string, any> | undefined;
|
|
660
|
-
/**
|
|
661
|
-
* @schema FirestartrGithubOrganizationSecretSectionSpecWriteConnectionSecretToRef
|
|
662
|
-
*/
|
|
663
|
-
export interface FirestartrGithubOrganizationSecretSectionSpecWriteConnectionSecretToRef {
|
|
664
|
-
/**
|
|
665
|
-
* @schema FirestartrGithubOrganizationSecretSectionSpecWriteConnectionSecretToRef#name
|
|
666
|
-
*/
|
|
667
|
-
readonly name: string;
|
|
668
|
-
/**
|
|
669
|
-
* @schema FirestartrGithubOrganizationSecretSectionSpecWriteConnectionSecretToRef#outputs
|
|
670
|
-
*/
|
|
671
|
-
readonly outputs: FirestartrGithubOrganizationSecretSectionSpecWriteConnectionSecretToRefOutputs[];
|
|
672
|
-
}
|
|
673
|
-
/**
|
|
674
|
-
* Converts an object of type 'FirestartrGithubOrganizationSecretSectionSpecWriteConnectionSecretToRef' to JSON representation.
|
|
675
|
-
*/
|
|
676
|
-
export declare function toJson_FirestartrGithubOrganizationSecretSectionSpecWriteConnectionSecretToRef(obj: FirestartrGithubOrganizationSecretSectionSpecWriteConnectionSecretToRef | undefined): Record<string, any> | undefined;
|
|
677
656
|
/**
|
|
678
657
|
* @schema FirestartrGithubOrganizationSecretSectionSpecSecretsActions
|
|
679
658
|
*/
|
|
@@ -799,19 +778,6 @@ export interface FirestartrGithubOrganizationSecretSectionSpecContextProvider {
|
|
|
799
778
|
* Converts an object of type 'FirestartrGithubOrganizationSecretSectionSpecContextProvider' to JSON representation.
|
|
800
779
|
*/
|
|
801
780
|
export declare function toJson_FirestartrGithubOrganizationSecretSectionSpecContextProvider(obj: FirestartrGithubOrganizationSecretSectionSpecContextProvider | undefined): Record<string, any> | undefined;
|
|
802
|
-
/**
|
|
803
|
-
* @schema FirestartrGithubOrganizationSecretSectionSpecWriteConnectionSecretToRefOutputs
|
|
804
|
-
*/
|
|
805
|
-
export interface FirestartrGithubOrganizationSecretSectionSpecWriteConnectionSecretToRefOutputs {
|
|
806
|
-
/**
|
|
807
|
-
* @schema FirestartrGithubOrganizationSecretSectionSpecWriteConnectionSecretToRefOutputs#key
|
|
808
|
-
*/
|
|
809
|
-
readonly key: string;
|
|
810
|
-
}
|
|
811
|
-
/**
|
|
812
|
-
* Converts an object of type 'FirestartrGithubOrganizationSecretSectionSpecWriteConnectionSecretToRefOutputs' to JSON representation.
|
|
813
|
-
*/
|
|
814
|
-
export declare function toJson_FirestartrGithubOrganizationSecretSectionSpecWriteConnectionSecretToRefOutputs(obj: FirestartrGithubOrganizationSecretSectionSpecWriteConnectionSecretToRefOutputs | undefined): Record<string, any> | undefined;
|
|
815
781
|
/**
|
|
816
782
|
* A reference to the Kubernetes Secret resource that contains the value.
|
|
817
783
|
*
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { EntityGHOrgSecretSection } from '.';
|
|
2
|
+
import { type OrgSecretsSection } from 'github';
|
|
3
|
+
export type SecretEntry = {
|
|
4
|
+
name: string;
|
|
5
|
+
ref: {
|
|
6
|
+
kind: string;
|
|
7
|
+
name: string;
|
|
8
|
+
key: string;
|
|
9
|
+
};
|
|
10
|
+
visibility: string;
|
|
11
|
+
selectedRepositories?: string[];
|
|
12
|
+
};
|
|
13
|
+
declare const SECTIONS: OrgSecretsSection[];
|
|
14
|
+
export { SECTIONS };
|
|
15
|
+
export declare function provisionOrgSecrets(entity: EntityGHOrgSecretSection, secrets: Record<string, SecretEntry[]>): Promise<void>;
|
|
16
|
+
export declare function adoptSecretsIfNeeded(entity: EntityGHOrgSecretSection, secrets: Record<string, SecretEntry[]>): Promise<void>;
|
|
@@ -2,7 +2,9 @@ import { createCheckRun } from './src/check_run';
|
|
|
2
2
|
import { upsertMultiPartStickyComments } from './src/sticky_comment';
|
|
3
3
|
import { getOctokitForOrg, getGithubAppToken, getOctokitFromPat } from './src/auth';
|
|
4
4
|
import { encryptRepoSecret, getRepoPublicKey } from './src/encrypt';
|
|
5
|
+
import { getOrgPublicKey, encryptOrgSecret, getOrgSecret } from './src/orgSecrets';
|
|
5
6
|
import type { RepoSecretsSection } from './src/encrypt';
|
|
7
|
+
import type { OrgSecretsSection } from './src/orgSecrets';
|
|
6
8
|
import type { WorkflowCompletionResult, WorkflowDispatchInputs, WorkflowRunConclusion, WorkflowRunStatus, WorkflowRunStatusFilter, WorkflowRunSummary } from './src/workflow';
|
|
7
9
|
import { withProfile } from './src/with_profile';
|
|
8
10
|
import { createProfile } from './src/profile';
|
|
@@ -103,10 +105,14 @@ declare const _default: {
|
|
|
103
105
|
encryption: {
|
|
104
106
|
encryptRepoSecret: typeof encryptRepoSecret;
|
|
105
107
|
getRepoPublicKey: typeof getRepoPublicKey;
|
|
108
|
+
getOrgPublicKey: typeof getOrgPublicKey;
|
|
109
|
+
encryptOrgSecret: typeof encryptOrgSecret;
|
|
110
|
+
getOrgSecret: typeof getOrgSecret;
|
|
106
111
|
};
|
|
107
112
|
withProfile: typeof withProfile;
|
|
108
113
|
createProfile: typeof createProfile;
|
|
109
114
|
};
|
|
110
115
|
export default _default;
|
|
111
|
-
export {
|
|
116
|
+
export { createProfile };
|
|
117
|
+
export type { RepoSecretsSection, OrgSecretsSection };
|
|
112
118
|
export type { WorkflowCompletionResult, WorkflowDispatchInputs, WorkflowRunConclusion, WorkflowRunStatus, WorkflowRunStatusFilter, WorkflowRunSummary, };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type OrgSecretsSection = 'actions' | 'dependabot' | 'codespaces';
|
|
2
|
+
export declare function getOrgPublicKey(org: string, section: OrgSecretsSection, octokit?: any): Promise<any>;
|
|
3
|
+
export declare function encryptOrgSecret(org: string, section: OrgSecretsSection, plaintextValue: string, preFetchedKey?: {
|
|
4
|
+
key_id: string;
|
|
5
|
+
key: string;
|
|
6
|
+
}, octokit?: any): Promise<{
|
|
7
|
+
key_id: any;
|
|
8
|
+
encrypted_value: string;
|
|
9
|
+
}>;
|
|
10
|
+
export declare function getOrgSecret(org: string, section: OrgSecretsSection, name: string, octokit?: any): Promise<any>;
|