gdc-cas
v0.1.0
Published
Node.js client library for Google Distributed Cloud air-gapped Certificate Authority Service (CAS)
Maintainers
Readme
Google Distributed Cloud air-gapped CAS Node.js Client
This package provides a Node.js client to interact with the Google Distributed Cloud air-gapped (GDC) Certificate Authority Service (CAS).
Installation
npm install gdc-casRuntime Requirements
- Node.js:
>= 22.19.0(LTS) - Versioning:
gdc-casfollows independent Semantic Versioning.
Prerequisites
- Create a Project in your GDC cluster.
- Follow the Manage service accounts steps to create a service account for your project:
- Assign the
certificate-authority-service-adminrole to your service account. - Generate a key pair for your service account and store the private key as a JSON file. This JSON file will be used by the CAS client to authenticate with GDC.
- Assign the
- Follow the CAS user guide to create Certificate Authorities(CAs) for your project. The CAs will be referenced by the CAS client when requesting certificates.
- Fetch GDC trust bundles for
trust-store-global-root-ext. The CAS client will need the trust bundle to connect to the GDC clusters.
Usage
Initialization
Provide the following configuration options to initialize the client:
import { CASClient } from 'gdc-cas';
const clientConfig = {
saFilePath: '/path/to/sa.json', // File path for the service account private key JSON file.
caFilePath: '/path/to/ca.crt', // File path for the GDC trust store.
zone: 'us-west6-a', // GDC zone name.
};
// Create and initialize the CASClient
const casClient = new CASClient(clientConfig);
await casClient.init();gRPC Mode (Bypass KRM)
By default, the client uses the Kubernetes API to manage certificate requests (KRM mode).
If you want to use the gRPC mode, initialize the client with useGrpc: true. This bypasses the Kubernetes API server and makes direct gRPC calls to the CAS proxy.
const clientConfig = {
saFilePath: '/path/to/sa.json',
caFilePath: '/path/to/ca.crt',
zone: 'us-west6-a',
useGrpc: true, // Enable direct gRPC calls
// casProxyUrl: 'https://cas.org.zone.domain.com' // Optional: Derived from token_uri if not specified
};
const casClient = new CASClient(clientConfig);
await casClient.init();[!NOTE] In gRPC mode, only
createCertificateRequestandcreateRevokeCertificateRequestare supported. Other KRM operations (getCertificateRequest,listCertificateRequests,deleteCertificateRequest,getCertificateAuthority) are not supported over gRPC.
Certificate Revocation over gRPC
To request certificate revocation over gRPC:
const revokeParams = {
certificate: tlsCrtPemString, // The PEM-encoded certificate string to revoke
reason: 'KEY_COMPROMISE', // The reason for revocation (RevocationReason enum or string)
};
try {
const revokeResult = await casClient.createRevokeCertificateRequest(project, revokeParams);
console.log('Successfully revoked certificate. Reason:', revokeResult.reason);
} catch (error) {
console.error('Revocation failed:', error.message);
}Certificate Revocation over KRM
To request certificate revocation using KRM:
const revokeParams = {
certificateRequestRef: {
name: 'original-certificate-request-name', // Name of the original CertificateRequest
namespace: project,
},
reason: 'KEY_COMPROMISE', // The reason for revocation (RevocationReason enum or string)
};
try {
const revokeResult = await casClient.createRevokeCertificateRequest(project, revokeParams, {
timeoutMs: 15000,
pollingIntervalMs: 200,
});
console.log('Successfully created RevokeCertificateRequest CR. Name:', revokeResult.revokeCertificateRequestName);
} catch (error) {
console.error('Revocation failed:', error.message);
}Certificate Requests and Revocation Management
The client supports the following methods to manage certificate requests and revocation:
createCertificateRequestcreateRevokeCertificateRequestgetRevokeCertificateRequestdeleteRevokeCertificateRequestlistRevokeCertificateRequestsgetCertificateRequestlistCertificateRequestsdeleteCertificateRequestgetCertificateAuthority
Local Development & Verification
1. Updating the Protocol Buffer
If you modify proto/cas.proto to add new endpoints, fields, or services, recompile the static JSON descriptor so the gRPC client can serialize payloads at runtime:
cd ./cas/gdc-cas
npm run build:protoNote: Commit the updated proto/cas-json.js file alongside your .proto changes (verified automatically in CI).
2. Running Unit, Type & Package Smoke Tests
cd ./cas/gdc-cas
npm ci
npm run check:types
npm test3. Releases & Publishing
Official releases of gdc-cas to npmjs.com are published exclusively through the repository's automated GitHub Actions release pipeline and Google OSS Exit Gate after passing GDC Air-gapped Staging integration verification. Do not run npm publish manually from a local workstation.
