certbotbot
Reference documentation for a modular Bash project
Loading...
Searching...
No Matches
Functions
retention.bash File Reference

Applies ADR-034 retention only to fully proven managed S3 copies. More...

Functions

int certbotbot_retention_error (String status, String message)
 Emit a fixed retention-stage diagnostic.
 
int certbotbot_retention_date_valid (String date)
 Validate a candidate eight-digit Gregorian UTC date without clock IO.
 
int certbotbot_retention_preflight ()
 Validate destructive scope and AWS CLI capabilities before S3 IO.
 
int certbotbot_retention_apply (String workspace, String bucket, String current)
 Validate complete listing, HEAD all matches, then conditionally prune.
 

Detailed Description

Applies ADR-034 retention only to fully proven managed S3 copies.

This implementation has no scheduled or automatic deletion authority. A positive, separately validated count opts into conditional deletion only following an acknowledged current PUT and a confirmed dated-backup PUT. Enumerating an entire S3 bucket, adopting an old template, deleting the current key, and deleting version IDs are explicitly forbidden.

ListObjectsV2 uses fixed JMESPath to encode one page into a bounded scalar line with explicit fields. URL-encoded keys containing any percent-escape are rejected instead of decoded, preventing unsafe delimiters in Bash. Every listed candidate is structurally checked, then independently HEAD verified before a single deletion is issued. Metadata and S3 ETags do not authenticate a writer; externally coordinated IAM permissions remain a required boundary. This module never logs raw S3 output or object keys.

Function Documentation

◆ certbotbot_retention_apply()

int certbotbot_retention_apply ( String  workspace,
String  bucket,
String  current 
)

Validate complete listing, HEAD all matches, then conditionally prune.

The existing AWS CLI renders one JMESPath scalar with five separators: truncated | token | page key count | encoding | prefix | comma keys. Requesting URL encoding ensures troublesome delimiter characters inside S3 keys are percent-encoded. Such keys fail the entire preflight, rather than being unescaped, split or accidentally adopted. A fixed query, explicit –no-paginate, strict schema, token-cycle detection and byte limits prevent incomplete or ambiguous pages from leading to deletion.

After the entire listing is checked, verify every exact date-shaped key through an independent managed v1 HeadObject, retaining its ETag. Sort verified copies by name-encoded UTC date, preserve newest N and this invocation's confirmed backup, and delete provisional old keys oldest first using the captured ETag as an S3 IfMatch precondition. An accepted DeleteObject must subsequently be confirmed absent by exact-key HEAD. Any uncertain result stops further mutation with no rollback.

Parameters
workspaceCaller-owned absolute private mode-0700 workspace.
bucketExisting selected S3 bucket; never list globally.
currentFrozen exact authoritative key, protected from deletion.
STDIN
Nothing is read from STDIN.
STDOUT
Nothing is written to STDOUT.
STDERR
Fixed nonsecret partial-success diagnostics only.
Returns
CERTBOTBOT_RETENTION_DELETED confirmed deletion count.
Return values
0No retention requested, or full guarded cleanup succeeded.
74After current/backup confirmed, cleanup failed or is uncertain.

◆ certbotbot_retention_date_valid()

int certbotbot_retention_date_valid ( String  date)

Validate a candidate eight-digit Gregorian UTC date without clock IO.

Parameters
dateEight byte YYYYMMDD string from an untrusted S3 key.
STDIN
Nothing is read from STDIN.
STDOUT
Nothing is written to STDOUT.
STDERR
Nothing is written to STDERR.
Return values
0The date is Gregorian-valid, including leap years.
1The date is incomplete, nondecimal or impossible.

◆ certbotbot_retention_error()

int certbotbot_retention_error ( String  status,
String  message 
)

Emit a fixed retention-stage diagnostic.

Parameters
statusDefined nonzero exit status, 64 or 74.
messageStatic error description without untrusted object data.
STDIN
Nothing is read from STDIN.
STDOUT
Nothing is written to STDOUT.
STDERR
One nonsecret diagnostic.
Return values
64Invalid retention configuration before remote work.
74Current/backup confirmed but retention failed or is uncertain.

◆ certbotbot_retention_preflight()

int certbotbot_retention_preflight ( )

Validate destructive scope and AWS CLI capabilities before S3 IO.

A count of zero does nothing. Positive retention requires a single contiguous {YEAR}{MONTH}{DOM}, a >=4 byte anchored literal prefix ending in - or _, and a single literal safe tar.gz suffix. Filename publication under ADR-032 intentionally permits a wider template set; that freedom does not grant the right to enumerate or delete old objects. The exact selected date/name must match this namespace and be different from the authoritative current key. AWS skeleton feature probes are local: unsupported conditional deletion fails before any S3 read or write.

STDIN
Nothing is read from STDIN.
STDOUT
Nothing is written to STDOUT.
STDERR
Static configuration error on failure.
Returns
Frozen CERTBOTBOT_RETENTION_PREFIX and _SUFFIX.
Return values
0A zero count or bounded eligible namespace.
64Invalid count, template, backend or CLI capabilities.