Skip to main content

Create

Creates a key pair for the specified service account.

import { cloudApi, serviceClients, Session } from "@yandex-cloud/nodejs-sdk";

const CreateKeyRequest = cloudApi.iam.key_service.CreateKeyRequest;
const KeyFormat = cloudApi.iam.key_service.KeyFormat;
const Key_Algorithm = cloudApi.iam.key.Key_Algorithm;

(async () => {
const authToken = process.env["YC_OAUTH_TOKEN"];
const session = new Session({ oauthToken: authToken });
const client = session.client(serviceClients.KeyServiceClient);

const result = await client.create(
CreateKeyRequest.fromPartial({
// serviceAccountId: "serviceAccountId",
// description: "description",
// format: KeyFormat.undefined,
// keyAlgorithm: Key_Algorithm.RSA_2048
})
);
console.log(result);
})();

CreateKeyRequest

serviceAccountId : string

ID of the service account to create a key pair for. To get the service account ID, use a yandex.cloud.iam.v1.ServiceAccountService.List request. If not specified, it defaults to the subject that made the request.

description : string

Description of the key pair.

format : KeyFormat

Output format of the key.

keyAlgorithm : Key.Algorithm

An algorithm used to generate a key pair of the Key resource.

CreateKeyResponse

key : Key

Key resource.

privateKey : string

A private key of the Key resource. This key must be stored securely.

Key

A Key resource. For more information, see Authorized keys.

Algorithm
  • ALGORITHM_UNSPECIFIED

  • RSA_2048

    RSA with a 2048-bit key size. Default value.

  • RSA_4096

    RSA with a 4096-bit key size.

id : string

ID of the Key resource.

One of subject

  • userAccountId : string

    ID of the user account that the Key resource belongs to.

  • serviceAccountId : string

    ID of the service account that the Key resource belongs to.

createdAt : google.protobuf.Timestamp

Creation timestamp.

description : string

Description of the Key resource. 0-256 characters long.

keyAlgorithm : Algorithm

An algorithm used to generate a key pair of the Key resource.

publicKey : string

A public key of the Key resource.

lastUsedAt : google.protobuf.Timestamp

Timestamp for the last use of this key.