
Security News
Node.js TSC Votes to Stop Distributing Corepack
Corepack will be phased out from future Node.js releases following a TSC vote.
@ibm-cloud/secrets-manager
Advanced tools
A Node.js client library to interact with the IBM Cloud® Secrets Manager APIs.
The IBM Cloud Secrets Manager Node.js SDK allows developers to programmatically interact with the following IBM Cloud services:
Service name | Import path |
---|---|
Secrets Manager | @ibm-cloud/secrets-manager/secrets-manager/v2 |
An IBM Cloud API key that allows the SDK to access your account.
Node.js version 16 or above.
This SDK is tested with Node versions 14 and up. The SDK may work on previous versions, but this is not supported officially.
npm install @ibm-cloud/secrets-manager
Secrets Manager uses token-based Identity and Access Management (IAM) authentication.
With IAM authentication, you supply an API key that is used to generate an access token. Then, the access token is included in each API request to Secrets Manager. Access tokens are valid for a limited amount of time and must be regenerated.
Authentication for this SDK is accomplished by
using IAM authenticators. Import
authenticators from @ibm-cloud/secrets-manager/auth
.
import { IamAuthenticator } from '@ibm-cloud/secrets-manager/auth';
const authenticator = new IamAuthenticator({
apikey: '{apikey}',
});
import { getAuthenticatorFromEnvironment } from '@ibm-cloud/secrets-manager/auth';
// env vars
// SECRETS_MANAGER_API_APIKEY==<apikey>
const iamAuthenticator = getAuthenticatorFromEnvironment('SECRETS_MANAGER_API');
To learn more about IAM authenticators and how to use them in your Node.js application, see the IBM Node.js SDK Core documentation.
serviceUrl
parameter to set the endpoint URL that is specific to your Secrets Manager service instance. To
find your endpoint URL, you can copy it from the Endpoints page in the Secrets Manager UI.Construct a service client and use it to create and retrieve a secret from your Secrets Manager instance.
const SecretsManager = require('@ibm-cloud/secrets-manager/secrets-manager/v2');
const { IamAuthenticator } = require('@ibm-cloud/secrets-manager/auth');
async function secretsManagerSdkExample() {
// Authenticate with IAM using your IBM Cloud API key
const authenticator = new IamAuthenticator({
apikey: process.env.SECRETS_MANAGER_API_APIKEY,
});
// Create an instance of the SDK by providing an authentication mechanism and your Secrets Manager instance URL
const secretsManager = new SecretsManager({
authenticator,
serviceUrl:
'https://example-instance.us-south.secrets-manager.appdomain.cloud',
});
// Use the Secrets Manager API to create a secret
let res = await secretsManager.createSecret({
secretPrototype: {
custom_metadata: { metadata_custom_key: 'metadata_custom_value' },
description: 'Description of my arbitrary secret.',
expiration_date: '2023-10-05T11:49:42Z',
labels: ['dev', 'us-south'],
name: 'example-arbitrary-secret',
secret_group_id: 'default',
secret_type: 'arbitrary',
payload: 'secret-data',
version_custom_metadata: { custom_version_key: 'custom_version_value' },
}
});
console.log('Secret created:\n' + JSON.stringify(res.result, null, 2));
// Get the ID of the newly created secret
const secretId = res.result.id;
// Use the Secrets Manager API to get the secret using the secret ID
res = await secretsManager.getSecret({
id: secretId,
});
console.log('Get secret:\n', JSON.stringify(res.result, null, 2));
}
secretsManagerSdkExample();
To delete a secret, specify its id
.
res = await secretsManager.deleteSecret({
id: secretId,
});
console.log('Secret deleted.');
Create a secret group, and then add a new secret to this group.
// Create a secret group
const createGroupParams = { name: 'Test Group', description: 'Group my test secrets' };
let res = await secretsManager.createSecretGroup(createGroupParams);
const secretGroupId = res.result.id;
// Create a secret and associate it with your secret group
res = await secretsManager.createSecret({
secretPrototype: {
secret_group_id: secretGroupId,
name: "Test secret",
description: 'Secret used for testing.',
username: 'test_user',
password: 'test_password',
labels: ['label1'],
expiration_date: '2030-04-01T09:30:00Z',
}
});
Create a rotation policy of one month for a secret.
let res = await secretsManager.createSecret({
secretPrototype: {
custom_metadata: { metadata_custom_key: 'metadata_custom_value' },
description: 'Description of my arbitrary secret.',
expiration_date: '2023-10-05T11:49:42Z',
labels: ['dev', 'us-south'],
name: 'example-arbitrary-secret',
secret_group_id: 'default',
secret_type: 'arbitrary',
payload: 'secret-data',
version_custom_metadata: { custom_version_key: 'custom_version_value' },
rotation: {
auto_rotate: true,
interval: 1,
unit: month,
}
}
});
For more information and IBM Cloud SDK usage examples for Node.js, see the IBM Cloud SDK Common documentation
This project includes unit tests test/unit
and integration tests test/integration
.
The integration tests are run against an actual Secrets Manager instance and require the following environment variables to be set:
SECRETS_MANAGER_API_APIKEY=<API_KEY>
SERVICE_URL=<SECRETS_MANAGER_ENDPOINT_URL>
To run the tests:
npm test
If you're having difficulties using this SDK, you can ask questions about this project by using Stack Overflow. Be sure to include
the ibm-cloud
and ibm-secrets-manager
tags.
You can also check out the Secrets Manager documentation and API reference for more information about the service.
If you encounter an issue with the project, you're welcome to submit a bug report to help us improve.
For general contribution guidelines, see CONTRIBUTING.
This SDK project is released under the Apache 2.0 license. The license's full text can be found in LICENSE.
FAQs
Client library for IBM Cloud Secrets Manager
The npm package @ibm-cloud/secrets-manager receives a total of 3,015 weekly downloads. As such, @ibm-cloud/secrets-manager popularity was classified as popular.
We found that @ibm-cloud/secrets-manager demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Corepack will be phased out from future Node.js releases following a TSC vote.
Research
Security News
Research uncovers Black Basta's plans to exploit package registries for ransomware delivery alongside evidence of similar attacks already targeting open source ecosystems.
Security News
Oxlint's beta release introduces 500+ built-in linting rules while delivering twice the speed of previous versions, with future support planned for custom plugins and improved IDE integration.