Skip to content

core: reuse credential dir across start and start-post if populated - #31202

Merged
bluca merged 5 commits into
systemd:mainfrom
YHNdnzj:creds-reuse
Feb 7, 2024
Merged

bluca merged 5 commits into
systemd:mainfrom
YHNdnzj:creds-reuse

Conversation

@YHNdnzj

@YHNdnzj YHNdnzj commented Feb 4, 2024 •

Copy link
Copy Markdown
Member

Currently, exec_setup_credential() always rewrite all credentials
upon exec_invoke(), i.e. invocation of each ExecCommand, and within
a single tmpfs instance. This is problematic though:

  • When writing each tmp cred file, we essentially double the size
    of the credential. Therefore, if one cred is bigger than half
    of CREDENTIALS_TOTAL_SIZE_MAX, confusing ENOSPC occurs (see also
    also provide credentials in ExecStartPre #24734 (comment))

  • Credential is a unit-wide thing and thus should not change
    during the whole lifetime of main process. However, if e.g.
    a on-disk credential or SetCredential= in unit file
    changes between ExecStart= and ExecStartPost=,
    the credentials are overwritten when the latter gets to run,
    and the already-running main process is suddenly seeing
    completely different creds.

So, let's try to reuse final cred dir if the main process has started
and the tmpfs has been populated, so that the creds used is stable
across all ExecStart= and ExecStartPost=-s. We still want to retain
the ability of updating creds through ExecStartPre= though, therefore
we forcibly use a fresh cred dir for those. 'Fresh' means to actually
unmount the old tmpfs first, so the first problem goes away, too.

Replaces #31201

@YHNdnzj YHNdnzj added the pid1 label Feb 4, 2024
@github-actions github-actions Bot added the tests label Feb 4, 2024
Comment thread test/units/testsuite-54.sh Fixed
Comment thread test/units/testsuite-54.sh Fixed
@poettering

Copy link
Copy Markdown
Member

TBH, I don't think this is supported/worth supporting... We don't document this at all, and as mentioned, creds passed to a unit should be stable IMO.

i have a blurry memory of someone doing exactly this/asking for this, so we supported this. too lazy to do a git log search, but i have a hazy idea, that this has came up before.

I agree that creds passed to a unit should be stable which is what my proposal would do – except that it limits that to the time window that starts when we switch from ExecStartPre= to ExecStart=, i.e. when the preparatory steps are over.

@poettering

Copy link
Copy Markdown
Member

You must have some dummy creds and then overwrite it in ExecStartPre=. That's already a bit weird?

The way I'd assume people us this is by populating /run/credstore/ from ExecStartPre= and then import it via ImportCredential= in a graceful matter? That isn#t weird at all?

@poettering

Copy link
Copy Markdown
Member

Or, maybe introduce a command prefix for "reloading creds"? If people really want that, but I doubt it?

I'd really not make that configurable, but simply say "in preparatory you have flexibility – but once you leave them things are immutable". Or in other words: on ExecStartPre= we reread creds each time, but on ExecStart=/ExecStartPost= we don't anymore, except for the first time.

@poettering poettering added reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks and removed please-review PR is ready for (re-)review by a maintainer labels Feb 6, 2024
@github-actions github-actions Bot added please-review PR is ready for (re-)review by a maintainer and removed reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels Feb 6, 2024
@YHNdnzj YHNdnzj changed the title core: reuse credential dir if mounted and non-empty core: reuse credential dir across start and start-post if populated Feb 6, 2024
@YHNdnzj
YHNdnzj force-pushed the creds-reuse branch 5 times, most recently from 343d292 to 6c9fc64 Compare February 6, 2024 16:04
Also rename EXEC_WRITE_CREDENTIALS to EXEC_SETUP_CREDENTIALS.
fresh otherwise

Currently, exec_setup_credential() always rewrite all credentials
upon exec_invoke(), i.e. invocation of each ExecCommand, and within
a single tmpfs instance. This is problematic though:

* When writing each tmp cred file, we essentially double the size
  of the credential. Therefore, if one cred is bigger than half
  of CREDENTIALS_TOTAL_SIZE_MAX, confusing ENOSPC occurs (see also
  systemd#24734 (comment))

* Credential is a unit-wide thing and thus should not change
  during the whole lifetime of main process. However, if e.g.
  a on-disk credential or SetCredential= in unit file
  changes between ExecStart= and ExecStartPost=,
  the credentials are overwritten when the latter gets to run,
  and the already-running main process is suddenly seeing
  completely different creds.

So, let's try to reuse final cred dir if the main process has started
and the tmpfs has been populated, so that the creds used is stable
across all ExecStart= and ExecStartPost=-s. We still want to retain
the ability of updating creds through ExecStartPre= though, therefore
we forcibly use a fresh cred dir for those. 'Fresh' means to actually
unmount the old tmpfs first, so the first problem goes away, too.
@poettering poettering added good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed and removed please-review PR is ready for (re-)review by a maintainer labels Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

5 participants