Say why a revoked login was revoked, and warn containers off copying one
Stacked on #854.
What
Copying one login into several containers is a common way to run the CLI unattended, and it can't work:
- Every refresh replaces the login's refresh token.
- When a replaced token comes back, Basecamp signs the whole login out as stolen.
That is the theft defense that rotation exists for, so the fix isn't to loosen rotation. It's to share one login, or use a credential that doesn't rotate, and to say so where the copies come from.
-
A login revoked for reuse says so. bc3 answers
invalid_grantwith "Token reuse detected, session terminated" the first time a replaced token comes back, and "Token has been revoked" after that. For those two, the CLI now says "This login was revoked, probably because it was used from more than one place: each refresh replaces its token, and Basecamp signs a login out when a replaced token comes back" instead of "Your session has expired or was revoked". The description only picks the wording. Whether the login is forgotten still depends on the error code alone (#854). -
Containers are warned once. On the first refresh inside a container, the CLI warns once not to copy the login into other containers, and says what to do instead:
- share one config directory as a volume (the credential lock is an
flockin that directory, so containers on one host take turns), or - set
BASECAMP_TOKENto a personal access token.
A container is detected by
/.dockerenv,/run/.containerenv,$container, orKUBERNETES_SERVICE_HOST. A marker file in the config directory keeps a scheduled job from printing it on every run. Inside a container, the revoked message ends with the same advice. - share one config directory as a volume (the credential lock is an
-
Docs. The README gets "Containers, CI and scheduled jobs", covering three ways to run unattended: a non-rotating token, one shared login, or one login per install. SECURITY.md now says not to copy
credentials.json.
Not done
-
Detecting a copied
credentials.json. I found no cheap signal that's also reliable:- A recreated container gets a new hostname, so a check would warn on every upgrade.
- Copying the whole config directory would carry any install id along with the login.
So this PR tells people instead of trying to detect it.
-
Recommending personal access tokens without a caveat. In bc3 they're staff-only for now, so the docs say "where your account offers them". Opening them up is a separate decision on the bc3 side.
Testing
internal/auth/container_test.go. These failed before the change:
TestRefresh_RevokedLoginSaysItWasUsedFromTwoPlaces(both descriptions)TestRefresh_RevokedLoginInAContainerSaysWhatToDoInsteadTestRefresh_InAContainerNoticesOnce
These guard behavior that should stay the same, and passed before as well:
-
TestRefresh_ExpiredLoginKeepsTheGeneralMessage -
TestRefresh_OutsideAContainerSaysNothing -
make checkpasses
Summary by cubic
Improves the message for a login revoked because it was copied into more than one place, and warns containers once not to do that.
Copying one login into several containers can't work: each refresh replaces its token, and two copies refreshing more than a minute apart get the whole login signed out. The CLI now explains that when bc3 refuses a refresh with "Token reuse detected" or "Token has been revoked" instead of the generic expiry message, and on the first refresh inside a container advises sharing one config directory as a volume on one host (with BASECAMP_NO_KEYRING=1; the flock credential lock serializes refreshes across containers on the same host, and no claim is made beyond) or setting BASECAMP_TOKEN to a non-rotating personal access token. The revoked message inside a container ends with the same advice.
- Detecting a copied
credentials.jsonis deliberately not attempted; the warning and docs say so instead. - Container detection covers Docker, Podman, systemd-nspawn, and Kubernetes markers; a marker in the config directory keeps the notice to one occurrence, and it repeats only if the marker can't be written.
- README gains a "Containers, CI and scheduled jobs" section; SECURITY.md says not to copy
credentials.json.