You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow restricting snapshot management commands to acting on preconfigured paths and backends #14562
Is your feature request related to a problem? Please describe.
Currently, cluster administrators can use the k3s etcd-snapshot CLI (or undocumented snapshot HTTP API) to create and delete snapshots against any local filesystem path or S3-compatible backend. The paths and/or backends do not necessarily have to be the same as those configured for scheduled snapshots, which allows administrators a high level of flexibility.
Describe the solution you'd like
Some administrators have asked for the ability to restrict on-demand snapshots and snapshot management commands (delete) to using the same snapshot directory and/or etcd backend configuration as scheduled snapshots. This offers administrators a sense of security in the form of knowing that etcd snapshots can only be created or deleted against predefined paths and backends, at the cost of reduced flexibility.
Describe alternatives you've considered
Not have this feature, and continue to allow administrators to create/delete snapshots against any path or storage backend.
changed the title [-]Allow restricting on-demand etcd snapshots to preconfigured paths and backends[/-][+]Allow restricting snapshot management commands to acting on preconfigured paths and backends[/+]on Aug 31, 2026
My suggestion for this would be to add an opt-in server setting such as --etcd-snapshot-restrict-destination. When enabled, the server's existing snapshot configuration would become the source of truth for all snapshot management operations (save, delete, prune, and list).
When the option is enabled, the /db/snapshot handler could validate the destination from the incoming SnapshotRequest before performing the requested operation.
For local snapshots, the requested directory should resolve to the same directory configured by EtcdSnapshotDir, including the default snapshot directory when no explicit directory is configured.
For S3 snapshots, the request should only be allowed when S3 is configured on the server, and the requested S3 destination should match the server's configured target, such as the endpoint, bucket, folder, region, and other fields that define where the snapshots are stored. For EtcdS3.ConfigSecret, the validation should use the server's active/resolved S3 configuration rather than relying on client-supplied credentials or endpoint settings.
I think this validation is better placed in the server handler rather than only in the CLI, since /db/snapshot can also be called directly without going through the CLI. It would also be useful to preserve EtcdSnapshotDir in withRequest() when SnapshotRequest.Dir is not provided, so requests without an explicit override naturally continue using the server's configured snapshot directory.
For delete, snapshot names should also be treated strictly as filenames rather than paths. This would prevent path traversal outside the validated snapshot directory, especially since the current implementation builds the deletion path using filepath.Join(snapshotDir, s).
The new restriction could default to false so existing behavior and scripts remain unchanged. When enabled, any explicit destination that differs from the server's configured destination would be rejected before the operation runs, while requests without overrides would continue using the existing server configuration.
Overall, this would give administrators an opt-in way to ensure that scheduled snapshots and on-demand snapshot management always operate against the same configured local directory and/or S3 backend, while keeping the current behavior unchanged for users who do not enable the restriction.
When the option is enabled, the /db/snapshot handler could validate the destination from the incoming SnapshotRequest before performing the requested operation.
For local snapshots, the requested directory should resolve to the same directory configured by EtcdSnapshotDir, including the default snapshot directory when no explicit directory is configured.
For S3 snapshots, the request should only be allowed when S3 is configured on the server, and the requested S3 destination should match the server's configured target, such as the endpoint, bucket, folder, region, and other fields that define where the snapshots are stored. For EtcdS3.ConfigSecret, the validation should use the server's active/resolved S3 configuration rather than relying on client-supplied credentials or endpoint settings.
I don't want to bike shed too much about the flag name at this point but... I don't know if we need separate flags for restricting the local path and the s3 config, or a single flag for both, or what.
An easier way to handle this would just be to validate that the data-dir and s3 config in the incoming request are empty/nil, and reject the request if they are not. Since the user-provided values are used to override the defaults, this would ensure that they are not modified, without having to do a bunch of extra work.
I could see wanting to allow users to manage snapshots UNDER the configured paths (any relative path or prefix that does not traverse outside the parent directory) but that would be more work than just requiring the users to not set the directory or endpoint. From a UX perspective, the CLI could avoid setting the affected values from config.yaml, if it sees the restriction flags present.
Alternately, the backend could just ignore the restricted fields, and add a warning header in the response (that is printed by the client) indicating that the snapshot is being saved with the defaults. There are warning header helpers in the Kubernetes codebase for this.
When the option is enabled, the /db/snapshot handler could validate the destination from the incoming SnapshotRequest before performing the requested operation.
For local snapshots, the requested directory should resolve to the same directory configured by EtcdSnapshotDir, including the default snapshot directory when no explicit directory is configured.
For S3 snapshots, the request should only be allowed when S3 is configured on the server, and the requested S3 destination should match the server's configured target, such as the endpoint, bucket, folder, region, and other fields that define where the snapshots are stored. For EtcdS3.ConfigSecret, the validation should use the server's active/resolved S3 configuration rather than relying on client-supplied credentials or endpoint settings.
I don't want to bike shed too much about the flag name at this point but... I don't know if we need separate flags for restricting the local path and the s3 config, or a single flag for both, or what.
An easier way to handle this would just be to validate that the data-dir and s3 config in the incoming request are empty/nil, and reject the request if they are not. Since the user-provided values are used to override the defaults, this would ensure that they are not modified, without having to do a bunch of extra work.
I could see wanting to allow users to manage snapshots UNDER the configured paths (any relative path or prefix that does not traverse outside the parent directory) but that would be more work than just requiring the users to not set the directory or endpoint. From a UX perspective, the CLI could avoid setting the affected values from config.yaml, if it sees the restriction flags present.
Alternately, the backend could just ignore the restricted fields, and add a warning header in the response (that is printed by the client) indicating that the snapshot is being saved with the defaults. There are warning header helpers in the Kubernetes codebase for this.
I went through the current snapshot request flow and your suggestions again, and I think I thought about a simpler implementation direction now.
My understanding is that we don't really need to compare the requested path/S3 config against the server config. Since SnapshotRequest.Dir and SnapshotRequest.S3 are used specifically as overrides, we can treat the presence of those fields as the thing we want to restrict.
So my current plan is:
Add an opt-in server setting for the restriction. I’m using --etcd-snapshot-restrict-destination as the working name for now, but I’m not attached to the name.
Store that setting in the server Control config.
In pkg/etcd/snapshot_handler.go, check the incoming SnapshotRequest before dispatching the operation. When the restriction is enabled, a non-empty Dir or non-nil S3 override would be rejected.
Keep withRequest() using the server's existing EtcdSnapshotDir and EtcdS3 when those fields are not present in the request, so the server configuration remains the source of truth.
In pkg/cli/etcdsnapshot/etcd_snapshot.go, handle the config-file case so that the CLI doesn't turn values from config.yaml into explicit overrides when the restriction is enabled. This seems important because commandSetup() currently populates SnapshotRequest.Dir and SnapshotRequest.S3 from the CLI/config.
Add tests around the handler for restricted/unrestricted requests, and integration coverage for the snapshot commands.
For delete, I also noticed the snapshot name is eventually passed through filepath.Join(snapshotDir, s), so I think it makes sense to make sure the supplied snapshot names are treated as filenames and can't escape the configured directory.
That would give us a pretty small enforcement point:
CLI / HTTP API
|
v
/db/snapshot
|
v
check restriction
| |
override? no override
| |
reject use server config
|
v
save/list/prune/delete
This also keeps the restriction on the server side, so calling /db/snapshot directly can't bypass it.
Does this sound like the direction you had in mind? If so, I’ll trace the exact config/CLI plumbing and start working from there.
&cli.StringSliceFlag{
Name: "etcd-snapshot-restrictions",
Usage: "(db) Enforce restrictions on snapshot configuration; when set the selected defaults cannot be overridden via 'etcd-snapshot' options (valid values: zero or more of 'snapshot-dir', 's3-endpoint', 's3-bucket', 's3-folder', 's3-proxy', 'all')",
Destination: &ServerConfig.EtcdSnapshotRestrictions,
},
For deletions, the command has not historically required that the user pass a full path, just the snapshot name. This MUST continue to work properly when deleting snapshots from S3. If S3 is enabled, the expectation is that the snapshot is deleted both from local disk, and S3.
Allowed; overrides function as in previous releases
✅ PASS
Key QA Findings & Notes
Non-Blocking Fallback Behavior:
When a restricted flag is supplied via CLI, K3s does not abort execution with a non-zero exit code. Instead, it logs a descriptive warning, ignores the unauthorized parameters, and falls back to the server-configured destination.
Template Output Differences:
Single flag override: msg="<flag> override ignored by server-side snapshot restrictions. Using the server-configured destination."
Multiple flag overrides: msg="restricted snapshot options were ignored: <flag1>, <flag2>. Using the server-configured snapshot destination."
Configuration Formatting Note:
Whitespace padding inside comma-separated strings (e.g., "flag1, flag2") is not automatically trimmed by the config parser and will cause validation errors during service initialization. Multi-flag restrictions must be defined as either standard YAML lists or unpadded CSV strings ("flag1,flag2").
Helper command:
$ k3s etcd-snapshot --helpNAME: k3s etcd-snapshot - Manage etcd snapshotsUSAGE: k3s etcd-snapshot [command options]COMMANDS: save Trigger an immediate etcd snapshot delete Delete given snapshot(s) ls, list, l List snapshots prune Remove snapshots that match the name prefix that exceed the configured retention count help, h Shows a list of commands or help for one commandOPTIONS: --etcd-snapshot-restrictions value [ --etcd-snapshot-restrictions value ] (db) Enforce restrictions on snapshot configuration; when set the selected defaults cannot be overridden via 'etcd-snapshot' options (valid values: zero or more of 'snapshot-dir', 's3-endpoint', 's3-bucket', 's3-folder', 's3-proxy', 'all')
Activity
[-]Allow restricting on-demand etcd snapshots to preconfigured paths and backends[/-][+]Allow restricting snapshot management commands to acting on preconfigured paths and backends[/+]sRiSh-JaNa-tech commentedon Sep 16, 2026
Hi team,
My suggestion for this would be to add an opt-in server setting such as
--etcd-snapshot-restrict-destination. When enabled, the server's existing snapshot configuration would become the source of truth for all snapshot management operations (save,delete,prune, andlist).When the option is enabled, the
/db/snapshothandler could validate the destination from the incomingSnapshotRequestbefore performing the requested operation.For local snapshots, the requested directory should resolve to the same directory configured by
EtcdSnapshotDir, including the default snapshot directory when no explicit directory is configured.For S3 snapshots, the request should only be allowed when S3 is configured on the server, and the requested S3 destination should match the server's configured target, such as the endpoint, bucket, folder, region, and other fields that define where the snapshots are stored. For
EtcdS3.ConfigSecret, the validation should use the server's active/resolved S3 configuration rather than relying on client-supplied credentials or endpoint settings.I think this validation is better placed in the server handler rather than only in the CLI, since
/db/snapshotcan also be called directly without going through the CLI. It would also be useful to preserveEtcdSnapshotDirinwithRequest()whenSnapshotRequest.Diris not provided, so requests without an explicit override naturally continue using the server's configured snapshot directory.For
delete, snapshot names should also be treated strictly as filenames rather than paths. This would prevent path traversal outside the validated snapshot directory, especially since the current implementation builds the deletion path usingfilepath.Join(snapshotDir, s).The new restriction could default to
falseso existing behavior and scripts remain unchanged. When enabled, any explicit destination that differs from the server's configured destination would be rejected before the operation runs, while requests without overrides would continue using the existing server configuration.Overall, this would give administrators an opt-in way to ensure that scheduled snapshots and on-demand snapshot management always operate against the same configured local directory and/or S3 backend, while keeping the current behavior unchanged for users who do not enable the restriction.
brandond commentedon Sep 16, 2026
I don't want to bike shed too much about the flag name at this point but... I don't know if we need separate flags for restricting the local path and the s3 config, or a single flag for both, or what.
An easier way to handle this would just be to validate that the data-dir and s3 config in the incoming request are empty/nil, and reject the request if they are not. Since the user-provided values are used to override the defaults, this would ensure that they are not modified, without having to do a bunch of extra work.
I could see wanting to allow users to manage snapshots UNDER the configured paths (any relative path or prefix that does not traverse outside the parent directory) but that would be more work than just requiring the users to not set the directory or endpoint. From a UX perspective, the CLI could avoid setting the affected values from config.yaml, if it sees the restriction flags present.
Alternately, the backend could just ignore the restricted fields, and add a warning header in the response (that is printed by the client) indicating that the snapshot is being saved with the defaults. There are warning header helpers in the Kubernetes codebase for this.
sRiSh-JaNa-tech commentedon Sep 17, 2026
I went through the current snapshot request flow and your suggestions again, and I think I thought about a simpler implementation direction now.
My understanding is that we don't really need to compare the requested path/S3 config against the server config. Since
SnapshotRequest.DirandSnapshotRequest.S3are used specifically as overrides, we can treat the presence of those fields as the thing we want to restrict.So my current plan is:
--etcd-snapshot-restrict-destinationas the working name for now, but I’m not attached to the name.Controlconfig.pkg/etcd/snapshot_handler.go, check the incomingSnapshotRequestbefore dispatching the operation. When the restriction is enabled, a non-emptyDiror non-nilS3override would be rejected.withRequest()using the server's existingEtcdSnapshotDirandEtcdS3when those fields are not present in the request, so the server configuration remains the source of truth.pkg/cli/etcdsnapshot/etcd_snapshot.go, handle the config-file case so that the CLI doesn't turn values fromconfig.yamlinto explicit overrides when the restriction is enabled. This seems important becausecommandSetup()currently populatesSnapshotRequest.DirandSnapshotRequest.S3from the CLI/config.For
delete, I also noticed the snapshot name is eventually passed throughfilepath.Join(snapshotDir, s), so I think it makes sense to make sure the supplied snapshot names are treated as filenames and can't escape the configured directory.That would give us a pretty small enforcement point:
This also keeps the restriction on the server side, so calling
/db/snapshotdirectly can't bypass it.Does this sound like the direction you had in mind? If so, I’ll trace the exact config/CLI plumbing and start working from there.
brandond commentedon Sep 17, 2026
I would suggest maybe something like:
For deletions, the command has not historically required that the user pass a full path, just the snapshot name. This MUST continue to work properly when deleting snapshots from S3. If S3 is enabled, the expectation is that the snapshot is deleted both from local disk, and S3.
mdrahman-suse commentedon Oct 13, 2026
QA Validation Report: etcd Snapshot Restrictions
PR: [k3s-io/k3s#14678](#14678)
Issue: [#14562](https://www.google.com/search?q=https://github.com/k3s-io/k3s/issues/14562)
Tested Commit:
82a6ddcd820bdfdd787455fae69e79afb5ef3102onmainbranchTest Date: October 12, 2026
Result: ✅ PASSED (All 12 Tests Passed)
Environment Details
INSTALL_K3S_COMMIT=82a6ddcd820bdfdd787455fae69e79afb5ef3102--cluster-init)Configurations Evaluated
etcd-snapshot-restrictions: "snapshot-dir"etcd-snapshot-restrictions: "s3-bucket,s3-folder"etcd-snapshot-restrictions: "all"etcd-snapshot-restrictions: ["snapshot-dir", "s3-bucket", "s3-proxy"]etcd-snapshot-restrictions: "snapshot-dir,s3-bucket,s3-proxy"Test Results
--etcd-snapshot-dirvia CLIsnapshot-dir override ignored by server-side snapshot restrictions...k3s etcd-snapshot save--etcd-s3-bucketon multi-flag configs3-bucket override ignored by server-side snapshot restrictions...--etcd-s3-folderon multi-flag configs3-folder override ignored by server-side snapshot restrictions...s3-bucket&s3-folder)restricted snapshot options were ignored: s3-bucket, s3-folder...--etcd-snapshot-dirsnapshot-dir override ignored...--etcd-s3-endpoints3-endpoint override ignored...--etcd-s3-proxys3-proxy override ignored...snapshot-dirsnapshot-dir override ignored...s3-proxys3-proxy override ignored...Key QA Findings & Notes
When a restricted flag is supplied via CLI, K3s does not abort execution with a non-zero exit code. Instead, it logs a descriptive warning, ignores the unauthorized parameters, and falls back to the server-configured destination.
msg="<flag> override ignored by server-side snapshot restrictions. Using the server-configured destination."msg="restricted snapshot options were ignored: <flag1>, <flag2>. Using the server-configured snapshot destination."Configuration Formatting Note:
Whitespace padding inside comma-separated strings (e.g.,
"flag1, flag2") is not automatically trimmed by the config parser and will cause validation errors during service initialization. Multi-flag restrictions must be defined as either standard YAML lists or unpadded CSV strings ("flag1,flag2").Helper command:
mdrahman-suse commentedon Oct 21, 2026
Closing as validate on the release branch commits