Skip to content

Terraform: add cert authority override support - #69623

Open
rosstimothy wants to merge 1 commit into
masterfrom
tross/tf_subca
Open

Terraform: add cert authority override support#69623
rosstimothy wants to merge 1 commit into
masterfrom
tross/tf_subca

Conversation

@rosstimothy

Copy link
Copy Markdown
Contributor

Closes #69591
Closes https://github.com/gravitational/core/issues/108

Changelog: Added cert_authority_override support to the Terraform provider,

Manual Test Plan

Test Environment

Local cluster and TF Provider built off this branch.

Test Cases

  • terraform apply creates an enabled db_client override; resource visible via tctl get cert_authority_override/db_client and tctl auth export serves the externally-signed chain
  • terraform plan shows no changes
  • In-place update of metadata.description
  • In-place update of certificate_overrides[0].disabled true/false on an active override
  • Changing sub_kind forces replacement
  • Changing metadata.name forces replacement
  • Data source reads the override by sub_kind
  • terraform import teleport_cert_authority_override.x db_client succeeds and no subsequent drift
  • Out-of-band change via tctl auth update-override is detected and reconciled when the field is explicitly set in config
  • Creating a second resource with a duplicate sub_kind fails ("exists in Teleport")
  • Create with metadata.name != cluster name rejected by server (incorrect cluster name)
  • Create with unsupported sub_kind rejected by server (invalid or unsupported sub_kind/caType)
  • Create with a certificate targeting an unknown CA key rejected by server (CRL creation fails) despite forced upsert
  • terraform destroy of a live enabled override succeeds and the resource is removed server-side

@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d3a2f3ef95

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

// Upsert updates a cert authority override.
func (r CertAuthorityOverrideClient) Upsert(ctx context.Context, override *subcav1.CertAuthorityOverride) error {
if _, err := r.client.SubCAClient().UpsertCertAuthorityOverride(ctx, &subcav1.UpsertCertAuthorityOverrideRequest{
CaOverride: override,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve CA override status when updating

When Terraform updates an existing CA override after Auth has populated status.public_key_hash_to_crl (the async CRL path used for disabled overrides in multi-Auth/HSM clusters), the plan decoded from Terraform has status omitted because it is excluded from the schema, and this Upsert sends that object as the full replacement. That can drop server-managed CRLs during a harmless metadata/spec reconciliation and corrupt the override's revocation state; preserve the prior status in PrepareUpdate or use a merge/granular update path.

AGENTS.md reference: AGENTS.md:L17-L17

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is moot, but the bot can't read e/ so it can't tell.

If no status is present in the request we'll simply use the last stored status. We do let callers supply the CRLs, and only the CRLs, so if you tctl get an old override you can re-create it verbatim.

https://github.com/gravitational/teleport.e/blob/c396029d68aa96db4efa4a8b1e64c73568ea4206/lib/subca/subcav1/service.go#L1041-L1053

@codingllama codingllama left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

I'm not sure about the Terraform boilerplate, as I haven't done this before, but the CertAuthorityOverride bits seem good to me.

Thanks for tackling this, Tim!

func (r CertAuthorityOverrideClient) Get(ctx context.Context, id tfdriver.NameIdentifier) (*subcav1.CertAuthorityOverride, error) {
resp, err := r.client.SubCAClient().GetCertAuthorityOverride(ctx, &subcav1.GetCertAuthorityOverrideRequest{
CaId: &subcav1.CertAuthorityOverrideID{
CaType: id.Name,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth saying, somewhere, that cert_authority_overrides are actually identified by sub_kind + name (ie, "ca type" + "cluster name"), but that for the RPCs here the current cluster is implied as the cluster name?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a sub_kind="windows" to the tests too, so we exercise multiple sub kinds?

Same for the manual test plan, would you mind testing with both db_client and windows overrides? You don't need to actually connect or anything, it's only to make sure that both overrides work together on Tf.

csr, err := x509.ParseCertificateRequest(block.Bytes)
s.Require().NoError(err)

rootKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the helpers at lib/subca/testenv help here?

func NewSelfSignedCA(optionalParams *CAParams) (*CA, error) {

func (ca *CA) NewIntermediateCA(optionalParams *CAParams) (*CA, error) {

func MakeCAChain(length int, optionalParams *CAParams) (CAChain, error) {


name := "teleport_cert_authority_override.test"

resource.Test(t, resource.TestCase{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we maybe write 2 overrides here? One db_client and one windows?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support cert_authority_override in the Terraform provider

2 participants