Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Machine ID: Per-ouput certificate_ttl and renewal_interval #51956

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

boxofrad
Copy link

@boxofrad boxofrad commented Feb 7, 2025

Implements #51560 by adding certificate_ttl and renewal_interval options to all tbot services/outputs, allowing you to control their certificate lifecycles separately from tbot's internal identity.

This is useful when you use tbot in one-shot mode to authenticate a cron job, because it enables you to set a long enough TTL on tbot's internal identity to survive until the next run, but a suitable short TTL on the workload's identity.

Example config:

# Controls `tbot`s internal identity certificate.
certificate_ttl: 1h
renewal_interval: 30m

services:
  - type: identity
    roles:
      - my-cron-job

    # Controls the output's certificate.
    certificate_ttl: 2m
    renewal_interval: 1m

changelog: tbot: support overriding certificate_ttl and renewal_interval on most outputs and services

}

if l.TTL < l.RenewalInterval && !oneShot {
log.WarnContext(
Copy link
Author

Choose a reason for hiding this comment

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

I re-homed these warnings from BotConfig.CheckAndSetDefaults.

Ideally, we'd return an error (so they'd get wrapped with the service[%d] prefix) but decided not to as making this a "hard fail" would be a breaking change.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would expect validate to return the error, a specific kind and the caller decides what to do with it.

There might be cases where an hard error is required

@boxofrad boxofrad force-pushed the boxofrad/tbot-per-service-cert-lifetimes branch from e568275 to 292ab59 Compare February 10, 2025 12:01
@boxofrad boxofrad force-pushed the boxofrad/tbot-per-service-cert-lifetimes branch from 292ab59 to 1787f24 Compare February 10, 2025 12:25
Copy link

github-actions bot commented Feb 10, 2025

Amplify deployment status

Branch Commit Job ID Status Preview Updated (UTC)
boxofrad/tbot-per-service-cert-lifetimes 599c8d7 2 ✅SUCCEED boxofrad-tbot-per-service-cert-lifetimes 2025-02-10 12:53:37

Comment on lines +108 to +110
func (o *WorkloadIdentityJWTService) GetCertificateLifetime() CertificateLifetime {
return CertificateLifetime{}
}
Copy link
Author

Choose a reason for hiding this comment

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

I didn't add it for this output because although there is a TTL, it felt wrong referring to it as the "certificate TTL" because it's really the JWT TTL.

Copy link
Contributor

Choose a reason for hiding this comment

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

What if we renamed certificate -> credential? That might make more sense in regards to both JWTs and X509? Imho, this is actually one of the more useful outputs to use this on since I'd expect a JWT to require a very short TTL (e.g 5 minutes).

Copy link
Author

Choose a reason for hiding this comment

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

Good point! Rename it just on this output, or on them all?

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably better to be consistent and rename on them all - but I can see how that creates a problem with the fields on the root configuration resource. I assume supporting both names on the root config would be challenging? We could deprecate the usage of certificate_ttl and encourage migration to credential_ttl. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 on renaming to be consistent

@boxofrad boxofrad force-pushed the boxofrad/tbot-per-service-cert-lifetimes branch from 03c6ed2 to 599c8d7 Compare February 10, 2025 12:50
@boxofrad boxofrad requested a review from strideynet February 10, 2025 12:51
@boxofrad boxofrad marked this pull request as ready for review February 10, 2025 12:53
Copy link
Contributor

Choose a reason for hiding this comment

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

Most of these outputs/services will have a test named something like TestApplicationOutput_YAML. That test usually has a "full" case where we try and set all of the possible config values. It'd be great to see the CertificateLifetime fields added to this. I've witnessed some really weird behaviour from our YAML marshal/unmarshaling libraries before, and those tests are fairly good at identifying when this happens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants