Deploying Scripts from CI
This guide sets up a script repository for one or more Remediation Orchestrator deployments.
Each tenant’s scripts live in their own directory, and CI turns them into
bundles and deploys them with maestroctl, the Remediation Orchestrator
command-line tool for script repositories:
- A merge request validates every changed bundle and shows a plan of what would change on each server.
- A merge to the default branch deploys the changed bundles.
The example pipeline uses GitLab CI, which the Remediation Orchestrator team
used for its own script repositories. The maestroctl commands don’t depend on
GitLab and run in any CI system. To use another CI system, replace the
GitLab-specific parts: the environment-scoped CI/CD variables, the id_tokens
that Teleport jobs use to join, the resource_group that runs one deploy at a
time, and the glab command in step 8. The example pipeline needs GitLab 17.7
or later.
Adding a deployment or tenant is a new directory. The pipeline finds it on its own.
1. Before you start
- Create two OAuth2 clients for CI that can use the client-credentials grant:
one for plan, mapped to the
viewerrole, and one for deploy, mapped to thescript-uploaderrole, in each tenant. Plan only reads, so a merge request never holds a credential that can deploy. See Authorization. Teleport deployments use Teleport bot identities instead. A Teleport identity carries its Teleport role names in the JWTrolesclaim. In each tenant, map the plan bot’s role toviewerand the deploy bot’s role toscript-uploaderwith[[rbac.role_mappings]]claim_role. - Add two masked CI/CD variables, both named
MAESTRO_SCRIPT_MANAGER_CLIENT_SECRET: one holding the plan client’s secret with environment scopemaestro-script-plan, and one holding the deploy client’s secret with environment scopemaestro-script-deploy, marked protected. GitLab gives each job the variable whose scope matches the job’senvironment. - Run the jobs on a glibc-based image such as
ubuntu:24.04.maestroctldoes not run on Alpine.
2. Create the repository
Create a repository with this layout. The next steps fill it in.
The directory path names each bundle: deployments/<deployment>/tenants/<tenant-id>/
holds the scripts for one tenant on one Remediation Orchestrator deployment.
Add maestro-repository.yaml at the root. It marks the repository root, and
every maestroctl scripts command reads the repository at -repository (the
current directory by default) and fails when the file is not there:
Add a .gitignore:
3. Add a deployment
For each Remediation Orchestrator server, create deployments/<deployment>/deployment.yaml. It
says how CI reaches the server, with one of the following authentication methods.
Unknown, missing, or mixed fields fail the pipeline.
3.1 bearer
bearer gets an OAuth2 access token and sends it in the Authorization
header:
maestroctl exchanges the client credentials in MAESTRO_TOKEN_URL,
MAESTRO_SCRIPT_MANAGER_CLIENT_ID, and MAESTRO_SCRIPT_MANAGER_CLIENT_SECRET
for one token per deployment, requesting maestro_api_scope. Without those
variables, such as on a developer’s machine, it sends your own token from
MAESTRO_TOKEN instead. A token fits one server, so -deployments must then
select a single deployment.
In-cluster ServiceAccount tokens
Kubernetes authentication is disabled by default. Enable it on the Remediation
Orchestrator server with MAESTRO_ENABLE_KUBERNETES_AUTH=true, set
MAESTRO_KUBERNETES_AUTH_ISSUER to the cluster’s ServiceAccount token issuer, and set
MAESTRO_KUBERNETES_AUTH_AUDIENCE to the audience requested by the caller’s
projected token. MAESTRO_KUBERNETES_AUTH_REVIEW_TIMEOUT defaults to 5s.
The server uses its own in-cluster credentials to call TokenReview and needs
Kubernetes RBAC permission to create authentication.k8s.io/tokenreviews.
Set MAESTRO_DISABLE_NVPROXY_AUTH=true and leave MAESTRO_ENABLE_OIDC_AUTH
disabled. The provider chain rejects Kubernetes authentication combined with
NVProxy or OIDC bearer authentication. Dex and Teleport authentication remain
supported.
The provider authenticates identity only. With Remediation Orchestrator RBAC enabled, configure the caller’s permissions in each tenant, for example:
For a short-lived upload job, read the projected token immediately before
invoking maestroctl:
Use a bearer deployment with an HTTPS URL. maestro_api_scope is still
required by the deployment schema, but is not used when MAESTRO_TOKEN supplies
the credential and client-credentials environment variables are unset. A
long-running uploader must reread the projected token as Kubernetes rotates it.
Enabling this provider does not enable HTTPS or Remediation Orchestrator
authorization.
3.2 teleport
teleport reaches the server through a local Teleport application tunnel,
which carries the identity, so maestroctl sends no token:
4. Add a tenant
For each tenant on the server, create
deployments/<deployment>/tenants/<tenant-id>/maestro.yaml:
scripts.root must be scripts, its default, so maestro.yaml can omit it.
Every .star file in scripts/ or one of its folders belongs to the tenant’s
bundle unless excluded by scripts.exclude; other files are ignored. A script’s
name is its path from scripts/, so scripts/plans/network/healthcheck.star is named
plans/network/healthcheck.star, and load() uses that name. Under
deployments/, a .star file anywhere else fails the pipeline. A bundle
needs at least one script, and a script name must end in .star and contain
exactly one period, so folder names cannot contain periods.
To keep tests alongside tenant scripts without uploading them, add exclusions:
Patterns use forward slashes and match paths relative to scripts.root.
* matches within one path component; ** matches across directories.
A matching directory and its contents are excluded. Patterns must be valid
relative globs without . or .. path components. Unmatched patterns are allowed.
Exclusions apply before scripts are parsed and their shared dependencies are resolved. A retained script that loads an excluded tenant script fails validation. Shared scripts referenced by retained scripts are still included.
Preparation retains excluded files, and scripts test can still discover and run
them. Validation, planning, deployment, and manifest-based test environments use
the filtered bundle. Exclusions are local source-selection settings and are not
sent to the server, so existing servers need no update. Scripts already stored on
the server remain governed by uploads_remove_omitted_scripts: excluding a local
file does not bypass the tenant’s policy for retaining omitted scripts.
Add a first script, such as scripts/greet.star from
Your First Script:
5. Optional: share scripts and templates
5.1 Shared scripts
To share scripts between tenants, put them in _shared/ and name them
shared_*.star. Tenant scripts must not use the shared_ prefix. A bundle includes the shared scripts its load()
statements reach, including shared scripts loaded by other shared scripts.
Shared scripts cannot load tenant scripts.
5.2 Template registry
Templates let one script run on several tenants with different settings. The pipeline renders them into each tenant’s bundle with
maestroctl scripts prepare, so a repository without templates needs no
changes.
List the templates and the tenants each renders for in
template_registry.bzl. A variant names one rendering, and
VARIANT_SCRIPT_DIRS maps it to a tenant’s scripts/ directory:
5.3 Templates and configs
_templates/health_check.template.star uses UPPER_CASE settings it does not
define:
_configs/health_check-default.config.star holds the defaults:
Each variant’s config overrides them. _configs/health_check-site-a.config.star:
_configs/health_check-site-b-team-x.config.star:
5.4 Rendering
For each variant, prepare writes <scripts directory>/health_check.star from
the defaults the variant does not override, then the variant’s config, then
the template. A variant can replace the whole template with
_templates/health_check-<variant>.template.star or its defaults with
_configs/health_check-<variant>-default.config.star. Configs may only assign
UPPER_CASE names, and every UPPER_CASE name a script uses must be assigned
before it. Do not commit the generated scripts: a file already at the output
path is an error.
6. Add the CI helpers
Copy these files into ci/ and make them executable.
6.1 with-teleport-app.sh
with-teleport-app.sh runs a maestroctl command through Teleport. It reads
the teleport_app of every Teleport deployment in .prepared-bundles/ with
yq, picks a free local port for each app,
starts one tbot with a tunnel per app, and adds -tunnel APP=ADDRESS to the
command for each one. A tunnel that is not ready within 30 seconds is left
out, so maestroctl fails only that deployment’s tenants and still runs
the rest. Without Teleport deployments it runs the command unchanged.
ci/with-teleport-app.sh
6.2 install-maestroctl.sh
install-maestroctl.sh downloads one maestroctl release from
MAESTROCTL_RELEASE_URL and checks it against a pinned checksum. A release
publishes maestroctl-linux-amd64, maestroctl-darwin-arm64, and a
SHA256SUMS file. Copy the checksums from SHA256SUMS into the script, and
update them together with the release URL. If your release location needs
authentication, add the header to the curl call.
ci/install-maestroctl.sh
6.3 install-tbot.sh
install-tbot.sh downloads the Teleport release archive of your Teleport
version from TBOT_ARCHIVE_URL, checks it against a pinned checksum, and
extracts tbot from it. Teleport publishes the archive at
https://cdn.teleport.dev/teleport-v<version>-linux-amd64-bin.tar.gz and its
checksum at the same URL with .sha256 appended. If you download it from a
mirror that needs authentication, add the header to the curl call.
ci/install-tbot.sh
7. Add the pipeline
Add this .gitlab-ci.yml at the repository root. Replace the example values in
variables, the plan and deploy client IDs, and for Teleport the join tokens
and the aud of TBOT_GITLAB_JWT.
.gitlab-ci.yml
8. Check it end to end
-
Open a merge request that adds a tenant. The
planjob lists, for each selected tenant, the scripts a deploy would create, update, or remove, and keeps each tenant’splan.jsonin itsresults/artifact. A deploy keeps live scripts that the bundle leaves out, so a tenant’s first deploy adopts the scripts that were uploaded another way. If the tenant config setsuploads_remove_omitted_scripts = true, a deploy removes those scripts instead. Review a tenant’s first plan before merging. -
Merge the merge request. The
deployjob on the default branch reconciles every tenant and keeps each tenant’sdeploy.jsonin itsresults/artifact. Every default-branch pipeline prepares every tenant so a later deployment also retries changes missed by an earlier failed or partially successful deployment. Merge request pipelines select only tenants affected by their diff. -
The first default-branch pipeline creates the
maestro-script-bundlesresource group. Only one deploy runs at a time. Set the group’s process mode tooldest_firstso deploys also run in commit order:
9. Reference
9.1 Commands
The pipeline runs five maestroctl scripts commands. Each takes the repository
with -repository and the deployments with -deployments, a glob of deployment.yaml files relative to the repository
such as deployments/*/deployment.yaml. Each match must be
deployments/<deployment>/deployment.yaml, and its tenants are the
tenants/<tenant-id>/maestro.yaml files beside it.
-
discoverprints the manifests of the tenants to act on, one per line. Without-changed-filesit prints every tenant. With-changed-files FILE, or-for standard input, it reads the NUL-separated paths thatgit diff --name-only -zwrites:- A change under a tenant directory selects that tenant.
- A change to
deployment.yamlselects every tenant in that deployment. - A change to
maestro-repository.yamlselects every tenant. - A change under
_shared/selects the tenants whose bundles load that script, and the tenants whose bundles fail to load. - A change under
_templates/or_configs/selects the tenants whose generated scripts read that file, or would read it if it existed. - A change to
template_registry.bzlselects the tenants whose generated scripts it adds, removes, or moves. This needs-base-registry FILE, the registry before the changes. Without it every tenant is selected. - Any other change selects nothing.
A glob that matches no
deployment.yamlis an error. Each-skip site-bor-skip site-a/defaultleaves that deployment or tenant out of the output, whatever selected it, and notes it on standard error. An entry that names no deployment or tenant the glob finds is an error. -
preparewrites the named tenants to.prepared-bundles/with their shared and generated scripts, theirdeployment.yaml, andmaestro-repository.yaml, so the output is a repository of its own. -
validate,plan, anddeployact on every tenant the glob matches, in parallel. Run them with-repository .prepared-bundles. A failing tenant lets the others finish, and the command then fails. With-results DIR, each tenant’svalidation.json,plan.json, ordeploy.jsonis written toDIR/<deployment>/<tenant-id>/. A glob that matches nothing leaves nothing to do and succeeds. -
deployplans each tenant and deploys the planned bundle. A tenant’s first deploy adopts the scripts that were uploaded another way, so review the plan in the merge request. -
plananddeploytake-tunnel APP=ADDRESSfor each Teleport application tunnel.
9.2 Jobs
discoverpipes the files changed since the merge request base tomaestroctl scripts discover, with the base commit’stemplate_registry.bzlwhen it has one. Default-branch pipelines select every tenant. A merge request also selects every tenant whenci/or.gitlab-ci.ymlchanged, or its base is not usable.maestroctl scripts preparethen stages the selected tenants in.prepared-bundles/for the later jobs.validatechecks each prepared bundle offline.planruns in merge requests and shows what a deploy would change on each server.deployruns on the default branch and reconciles every tenant, one deploy at a time.
The server validates each bundle and applies it as a unit, and deploying a bundle that is already live changes nothing.
9.3 Add a deployment or tenant
For a new tenant, create deployments/<deployment>/tenants/<tenant-id>/ with
its maestro.yaml and scripts/. For a new deployment, also add
deployments/<deployment>/deployment.yaml. The pipeline does not change.