-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Enroll admin/user and store creds on SecretsManager
- Loading branch information
1 parent
8c4765d
commit 484aa81
Showing
15 changed files
with
827 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module.exports = { | ||
"env": { | ||
"browser": false, | ||
"commonjs": false, | ||
"es2021": true, | ||
}, | ||
"extends": "airbnb", | ||
"parserOptions": { | ||
"ecmaVersion": 13, | ||
}, | ||
"rules": { | ||
"max-len": ["error", { | ||
"code": 120, | ||
}], | ||
"no-console": "off", | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const FabricCAClient = require('fabric-ca-client'); | ||
const utilities = require('./utilities'); | ||
|
||
// Extract environment variables | ||
const adminPasswordArn = process.env.ADMIN_PASSWORD_ARN; | ||
const caEndpoint = process.env.CA_ENDPOINT; | ||
const privateKeyArn = process.env.PRIVATE_KEY_ARN; | ||
const signedCertArn = process.env.SIGNED_CERT_ARN; | ||
const tlsCertBucket = process.env.TLS_CERT_BUCKET; | ||
const tlsCertKey = process.env.TLS_CERT_KEY; | ||
|
||
const caUrl = `https://${caEndpoint}`; | ||
const caName = utilities.getCaName(caEndpoint); | ||
|
||
// Enroll the admin only on creation | ||
exports.handler = async (event) => { | ||
if (event.RequestType === 'Create') { | ||
try { | ||
// Get the TLS cert from S3 | ||
const caTlsCert = await utilities.getS3Object(tlsCertBucket, tlsCertKey); | ||
// Get the admin credentials from Secrets Manager | ||
const adminPwd = await utilities.getSecret(adminPasswordArn); | ||
// Create a new client for interacting with the CA | ||
const ca = new FabricCAClient(caUrl, { trustedRoots: caTlsCert, verify: false }, caName); | ||
// Enroll the admin user, and import the new identity into Secrets Manager | ||
const enrollment = await ca.enroll({ enrollmentID: 'admin', enrollmentSecret: adminPwd }); | ||
await utilities.putSecret(privateKeyArn, enrollment.key.toBytes()); | ||
await utilities.putSecret(signedCertArn, enrollment.certificate); | ||
} catch (error) { | ||
console.error(`Failed to enroll admin user: ${error}`); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "fabric", | ||
"version": "0.0.1", | ||
"dependencies": { | ||
"@aws-sdk/client-s3": "3.53.1", | ||
"@aws-sdk/client-secrets-manager": "3.53.0", | ||
"fabric-ca-client": "2.2.11", | ||
"fabric-common": "2.2.11" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^8.11.0", | ||
"eslint-config-airbnb": "^19.0.4" | ||
} | ||
} |
Oops, something went wrong.