bootstrap

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 31 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Bootstrap template

bootstrap-template.yaml is copied verbatim from the CDK CLI's packages/aws-cdk/lib/api/bootstrap/bootstrap-template.yaml in aws/aws-cdk-cli, at the commit pinned in cmd/walle/internal/upstream and recorded in the upstream baseline. The package embeds it and deploys it as the default bootstrap template, so its bytes are what CloudFormation receives, and it carries no licence comment of its own (L.6-D4).

Do not edit it by hand. To refresh it after moving the pin, run the command below and review the diff:

./walle upstream bootstrap

Licence

The template is part of the AWS Cloud Development Kit (AWS CDK), Copyright 2018-2025 Amazon.com, Inc. or its affiliates, and is licensed under the Apache License, Version 2.0. See the CLI's LICENSE and NOTICE at the pinned commit, and this repository's NOTICE.

Documentation

Overview

Package bootstrap is the toolkit's side of the bootstrap contract it shares with the CDK CLI: reading an environment's toolkit stack and bootstrap version, as upstream's api/environment and toolkit-info.ts do (Epic E's EE-2).

A Registry lives for one action, as upstream's EnvironmentResourcesRegistry does, and caches each environment's toolkit stack and the SSM version parameters read in it, by account and region, so that deploying many stacks reads them once. Its Environment values check a stack's required bootstrap version, give the toolkit stack's outputs, and decide whether assets may be published across accounts.

The contract's names must match the CLI's exactly: the toolkit stack (CDKToolkit by default), its outputs BucketName, BucketDomainName, ImageRepositoryName and BootstrapVersion, its BootstrapVariant parameter, and the version gates. Upstream's behaviour is mirrored, including where it is lenient:

  • a toolkit stack that can't be looked up, for any reason but a cancelled context, is "not found", and the lookup's error is reported only when something needs the stack (E.1-D3);
  • when reading the SSM version parameter is denied, the toolkit stack's BootstrapVersion output is used instead, but only below version 5, the version that granted ssm:GetParameter (E.1-D1);
  • version numbers are read as JavaScript's parseInt reads them, so " 21" and "21abc" are 21 (E.1-D2);
  • the cross-account check fails open (E.1-D4).

Deploy deploys the bootstrap stack, as upstream's Bootstrapper and BootstrapStack do (Epic E's E.2). The template is upstream's, copied at the pinned commit by `./walle upstream bootstrap` and embedded (E.2-D1). The parameters are merged with the deployed stack's, validated and refused as upstream does, with its messages, so that a stack bootstrapped by either the toolkit or the CDK CLI bootstraps again with the other without losing trust, policies, the KMS key or the boundary (E.2-D2); a refusal is a warning and a no-op, not an error. The stack is deployed through a change set, from an assembly of the template written to a temporary directory, as upstream's is; an unchanged stack is skipped unless forced, by G.6's check, with no change set. The example permissions boundary is created as upstream creates it, denying the creation of roles and users without it, as the bootstrap template's copy does; upstream's policy denied nothing until aws-cdk-cli#2126 (E.2-D3). It departs from upstream in four places:

  • when no boundary is given, a deployed boundary is warned of as removed only when it is, with the other parameters taking the template's defaults; upstream warns of it whenever no boundary is given, though the parameter otherwise keeps its previous value (E.2-D2, as amended);
  • in the same way, ApplyPermissionsBoundaryToAllRoles turned on is warned of as having no effect only when no boundary is in effect, neither given nor deployed; upstream warns whenever no boundary is given (#39);
  • a template that doesn't declare ApplyPermissionsBoundaryToAllRoles, when the option is set, is refused before any IAM call, and so before the boundary's name is validated or its change warned of; upstream's does all three first, creating the example boundary (#39);
  • a deployment that ends paused, needing a rollback, is an error with Code "UnexpectedDeployResult", as upstream's is, but its change set is deleted first.

Upstream's leniency is kept in naming the example boundary with the qualifier given, or the default one, not the deployed stack's.

Index

Constants

View Source
const DefaultToolkitStackName = "CDKToolkit"

DefaultToolkitStackName is the toolkit stack's name when none is given.

View Source
const (

	// DefaultVariant is the bootstrap variant of a toolkit stack that doesn't say.
	DefaultVariant = "AWS CDK: Default Resources"
)

The names in the bootstrap template that the toolkit reads.

View Source
const RollbackVersion = 23

RollbackVersion is the bootstrap version that rolling back a stack needs: upstream's BOOTSTRAP_STACK_VERSION_FOR_ROLLBACK.

Variables

This section is empty.

Functions

func DefaultTemplate

func DefaultTemplate() (*cfntemplate.Object, error)

DefaultTemplate returns the bootstrap template the CDK CLI at the pinned commit deploys, parsed afresh, so the caller may change it.

func LoadTemplate

func LoadTemplate(name string) (*cfntemplate.Object, error)

LoadTemplate reads a bootstrap template from the named file, as YAML or JSON: upstream's loadStructuredFile.

func TemplateVariant

func TemplateVariant(t *cfntemplate.Object) string

TemplateVariant returns the bootstrap variant a template deploys, its BootstrapVariant parameter's default, or DefaultVariant: upstream's bootstrapVariantFromTemplate.

func TemplateVersion

func TemplateVersion(t *cfntemplate.Object) int

TemplateVersion returns the bootstrap version a template deploys, from its BootstrapVersion output's value or its CdkBootstrapVersion resource's, or 0 when it has neither: upstream's bootstrapVersionFromTemplate. A string value is read as parseInt reads it.

Types

type DeployOptions

type DeployOptions struct {
	// CFN and IAM are the clients of the environment, with the credentials to deploy in it.
	CFN deploy.CloudFormation
	IAM IAM

	IO *iohelper.Helper

	// Environment is the environment to bootstrap, resolved, and Partition the partition of its credentials.
	Environment cloudassembly.Environment
	Partition   string

	// ToolkitStackName is the bootstrap stack's name; empty means [DefaultToolkitStackName].
	ToolkitStackName string

	// Template is the bootstrap template.
	Template *cfntemplate.Object

	Parameters Parameters

	// ReplaceExisting drops the deployed values of the template's parameters that Parameters doesn't set, so that they take the template's defaults: upstream's BootstrapStackParameters.exactly.
	ReplaceExisting bool

	// NoExecute leaves the change set for someone else to execute.
	NoExecute bool

	Tags []types.Tag

	// TerminationProtection, when set, turns the stack's termination protection on or off; nil keeps the deployed stack's, or off for a new stack.
	TerminationProtection *bool

	// Force deploys over a stack of another variant or a higher version.
	Force bool

	Express bool
}

DeployOptions are the options for Deploy.

type Environment

type Environment struct {
	// contains filtered or unexported fields
}

Environment is an environment's bootstrapping, read with one set of credentials and cached in its Registry: upstream's EnvironmentResources.

func (*Environment) AllowCrossAccountAssetPublishing

func (e *Environment) AllowCrossAccountAssetPublishing(ctx context.Context) (bool, error)

AllowCrossAccountAssetPublishing reports whether assets may be published to this environment with credentials from another account: upstream's determineAllowCrossAccountAssetPublishing.

It reads the toolkit stack with DescribeStacks, because a deploy role can't list a stack's resources. Publishing is allowed when the BucketName output doesn't look like a bucket name, which means the bucket was left out on purpose, as a customised template may leave it empty, or put '-' or '***' there; or when the bootstrap version is at least 21, which prevents it at the IAM level. It is also allowed when the check fails, such as when the stack can't be read, with debug messages saying so, because many organisations create bootstrap resources their own way (E.1-D4).

func (*Environment) Toolkit

func (e *Environment) Toolkit(ctx context.Context) (*ToolkitInfo, error)

Toolkit returns the environment's toolkit stack, waiting for any operation on it to finish, as upstream's ToolkitInfo.lookup does. It looks the stack up once per environment in the registry, and returns the same result after that, found or not.

A stack that doesn't exist, or whose creation failed, is not found. So is one that couldn't be looked up, whose error is kept for the methods that need the stack; but when ctx is done, Toolkit returns the error, and keeps nothing.

func (*Environment) ValidateStackVersion

func (e *Environment) ValidateStackVersion(ctx context.Context, stackName string, expected *int, parameter string) error

ValidateStackVersion is Environment.ValidateVersion for a stack: upstream's Deployments.validateBootstrapStackVersion. A failure is a cdkerr.Error of Code "BootstrapVersionValidation" whose message starts with the stack's name, and whose cause is ValidateVersion's error, which carries the environment when it is a bootstrap error.

Rolling back a stack checks RollbackVersion with it.

func (*Environment) ValidateVersion

func (e *Environment) ValidateVersion(ctx context.Context, expected *int, parameter string) error

ValidateVersion checks that the environment's bootstrap version is at least expected, or does nothing when expected is nil: upstream's validateVersion.

It reads the version from the named SSM parameter, or, when parameter is empty, from the toolkit stack's BootstrapVersion output. When reading the parameter is denied, it uses the output instead, with a warning, if that is below 5, the version that granted ssm:GetParameter; otherwise it fails with Code "BootstrapVersionSsmConfirmationFailed".

It fails with a cdkerr.Error of Kind cdkerr.KindBootstrap and Code "OutdatedBootstrapStack", whose Environment is this one, when the version is too old; and with the errors of Environment.VersionFromSSMParameter and ToolkitInfo.

func (*Environment) VersionFromSSMParameter

func (e *Environment) VersionFromSSMParameter(ctx context.Context, parameter string) (int, error)

VersionFromSSMParameter reads the bootstrap version in the named SSM parameter, as parseInt reads it, once per environment in the registry.

It fails with a cdkerr.Error of Kind cdkerr.KindBootstrap and Code "SsmParameterNotFound", whose Environment is this one, when there is no such parameter, and with Code "SsmParameterNotANumber" when its value isn't a number.

type IAM

type IAM interface {
	GetPolicy(ctx context.Context, in *iam.GetPolicyInput, opts ...func(*iam.Options)) (*iam.GetPolicyOutput, error)
	CreatePolicy(ctx context.Context, in *iam.CreatePolicyInput, opts ...func(*iam.Options)) (*iam.CreatePolicyOutput, error)
}

IAM is the part of the IAM API the package uses, to create the example permissions boundary.

type Parameters

type Parameters struct {
	BucketName string
	KMSKeyID   string

	// CreateCustomerMasterKey, when set, creates a customer managed key for the bucket, or uses the AWS managed key; nil means the deployed stack's choice, or the AWS managed key for a new stack.
	CreateCustomerMasterKey *bool

	TrustedAccounts                 []string
	TrustedAccountsForLookup        []string
	UntrustedAccounts               []string
	CloudFormationExecutionPolicies []string
	Qualifier                       string

	// NoPublicAccessBlockConfiguration turns off the bucket's public access block, which is on unless this is set.
	NoPublicAccessBlockConfiguration bool

	ExamplePermissionsBoundary bool
	CustomPermissionsBoundary  string

	// ApplyPermissionsBoundaryToAllRoles, when set, applies the permissions boundary to every bootstrap role, not only the CloudFormation execution role, or to that one alone; nil means the deployed stack's choice, or the template's default, off, for a new stack or with [DeployOptions.ReplaceExisting].
	// Setting it, either way, needs a template that declares the parameter.
	ApplyPermissionsBoundaryToAllRoles *bool
}

Parameters are what a bootstrap deployment sets in the bootstrap template: upstream's BootstrappingParameters. A nil list means the deployed stack's value; an empty one means none.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry caches what the toolkit reads about each environment's bootstrapping, for one action: upstream's EnvironmentResourcesRegistry. It is safe for concurrent use.

func NewRegistry

func NewRegistry(toolkitStackName string, io *iohelper.Helper, opts ...RegistryOption) *Registry

NewRegistry returns a registry for environments whose toolkit stack is named toolkitStackName, or DefaultToolkitStackName when it is empty.

func (*Registry) For

For returns env, a resolved environment, read with cfg's credentials.

func (*Registry) VersionFromSSMParameter

func (r *Registry) VersionFromSSMParameter(ctx context.Context, t awsauth.Target, parameter string) (int, error)

VersionFromSSMParameter reads the bootstrap version in the named SSM parameter of t's environment, with t's credentials, as awsauth.Access.ForLookup needs it.

type RegistryOption

type RegistryOption func(*Registry)

RegistryOption is an option of NewRegistry.

func WithVersionRecorder

func WithVersionRecorder(record func(env cloudassembly.Environment, version int, ok bool)) RegistryOption

WithVersionRecorder makes the registry call record with each bootstrap version that its environments' version checks read, and whether it is a number, before the check can fail: upstream's validateVersion adds each version it reads to the notices, if there are any. The environment is the one the check read; record may be called from several goroutines at once.

type Result

type Result struct {
	// NoOp says nothing changed.
	NoOp bool

	// StabilizingResources are the resources that express mode reported complete while they were still settling.
	StabilizingResources []stackevents.StabilizingResource
}

Result is the outcome of Deploy.

func Deploy

func Deploy(ctx context.Context, o DeployOptions) (Result, error)

Deploy bootstraps an environment: it merges the parameters with the deployed bootstrap stack's, validates them, and deploys the template through a change set, as upstream's modernBootstrap and BootstrapStack.update do (E.2-D2).

The validation fails with a cdkerr.KindToolkit error whose Code is upstream's: "ConflictingKmsKeyOptions", "AccountBothTrustedAndUntrusted", "MissingExecutionPoliciesForTrust", "PermissionsBoundaryAllRolesNotSupported", "InvalidPermissionBoundaryName", "PermissionBoundaryRetrievalFailed" or "PermissionBoundaryCreateFailed". Unless forced, a deployed stack of another variant, or of a higher version, is left alone with a warning, and the result is a no-op, as upstream's is.

The example permissions boundary, cdk-<qualifier>-permissions-boundary, is created when missing, with upstream's policy: its DenyAccessIfRequiredPermBoundaryIsNotBeingApplied statement denies creating roles and users without the boundary, as the bootstrap template's copy of it does (E.2-D3). A boundary that exists is used as it is.

Parameters.ApplyPermissionsBoundaryToAllRoles, when set, needs a template that declares the parameter; one that doesn't is refused before any IAM call, and so before a custom boundary's name is validated or a change of boundary is warned of, where upstream refuses it after all three, once the example boundary is created (#39). Turned on with no boundary in effect, neither given nor deployed, it is warned of as having no effect; upstream warns whenever no boundary is given, though a deployed one is kept unless the parameters are replaced (#39, as E.2-D2 is amended).

type SSM

type SSM interface {
	GetParameter(ctx context.Context, in *ssm.GetParameterInput, opts ...func(*ssm.Options)) (*ssm.GetParameterOutput, error)
}

SSM is the part of the SSM API the package uses.

type ToolkitInfo

type ToolkitInfo struct {
	// StackName is the toolkit stack's name.
	StackName string
	// contains filtered or unexported fields
}

ToolkitInfo is an environment's toolkit stack, or the fact that it wasn't found: upstream's ToolkitInfo. A toolkit stack that wasn't found isn't an error until something needs it: then its methods fail with the reason.

func (*ToolkitInfo) BucketName

func (i *ToolkitInfo) BucketName() (string, error)

BucketName returns the name of the staging bucket, from the BucketName output.

func (*ToolkitInfo) BucketURL

func (i *ToolkitInfo) BucketURL() (string, error)

BucketURL returns the staging bucket's URL, https:// and the BucketDomainName output.

func (*ToolkitInfo) Found

func (i *ToolkitInfo) Found() bool

Found reports whether the toolkit stack was found.

func (*ToolkitInfo) RepositoryName

func (i *ToolkitInfo) RepositoryName() (string, error)

RepositoryName returns the name of the container image repository, from the ImageRepositoryName output.

func (*ToolkitInfo) Stack

func (i *ToolkitInfo) Stack() (*cfnstack.Stack, error)

Stack returns the toolkit stack.

func (*ToolkitInfo) Variant

func (i *ToolkitInfo) Variant() (string, error)

Variant returns the bootstrap variant, from the BootstrapVariant parameter, or DefaultVariant when there is no such parameter.

func (*ToolkitInfo) Version

func (i *ToolkitInfo) Version() (int, error)

Version returns the bootstrap version, from the BootstrapVersion output, read as parseInt reads it: 0 when there is no such output. It fails with Code "InvalidBootstrapVersion" when the output isn't a number.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL