-
Notifications
You must be signed in to change notification settings - Fork 56
Description
Summary of the new feature / enhancement
Context
Following is a comment on the proposed implementation for the get operation of the sshdconfig resource (see #1004):
- if no input is provided, get returns all settings from SSHD -T including defaults
- if input is provided, get returns the subset of settings from SSHD -T included in the input
- if
defaults: falseis passed in via_metadata, get returns the subset of settings fromSSHD -Tthat are not defaults- if
filepath: <filepath>is passed in via_metadata, get runsSSHD -T -f <filepath>The differing behavior for input/no-input in the
getoperation here is a break from prior design, user expectation, and integration with higher order tooling. Typically,getoperations return the full configurable state for a resource instance. This filtering makes more sense to me for theexportoperation. This design also prevents me from retrieving the full configuration but only verifying or enforcing a specific subset.Similarly, here we seem to be defining write-only properties (behavior-modifying parameters) to be passed through
_metadata. Arguably,filepathis a non-required key property - I would expect a configuration document containing any two instances of this resource with the samefilepath(orfilepathnot being defined) to raise a conflict in the future.
Originally posted by @michaeltlombardi in #1004 (comment)
Proposal
Circling back to this from a design discussion, I would propose that the resource:
- Define the read-only
defaultSettingsproperty as an array of property names. - Indicate whether the resource should explicitly export default settings with a write-only
exportDefaultsproperty.
Note
I'm using the property names defaultSettings and exportDefaults for convenience. The actual implemented names should be more thoroughly discussed.
Output for the get operation
When the get operation is invoked1, the resource returns every configuration setting. The defaultSettings property indicates which settings were provided as defaults by SSHD.
sshdconfig getport:
- 22
addressfamily: any
listenaddress:
- 0.0.0.0:22
- '[::]:22'
logingracetime: 120
x11displayoffset: 10
maxauthtries: 6
syslogfacility: LOCAL0
authorizedkeysfile:
- .ssh/authorized_keys
defaultSettings:
- port
- addressfamily
- listenaddress
- logingracetime
- x11displayoffset
- maxauthtriesBehavior for export
When defining the resource for the export operation, the exportDefaults write-only property changes the result object:
-
Without the
exportDefaultsproperty defined, the output includes only the explicitly set properties:sshdconfig export
syslogfacility: LOCAL0 authorizedkeysfile: - .ssh/authorized_keys
-
With
exportDefaultsdefined astrue, theexportoperation returns the effective configuration - when used inset, it will explicitly define each of these settings:sshdconfig export --input '{"exportDefaults": true}'
port: - 22 addressfamily: any listenaddress: - 0.0.0.0:22 - '[::]:22' logingracetime: 120 x11displayoffset: 10 maxauthtries: 6 syslogfacility: LOCAL0 authorizedkeysfile: - .ssh/authorized_keys
Note that it doesn't define the
defaultSettingsproperty - because for the exported instance, none of the settings are default.The documentation for the
exportDefaultswrite-only property should indicate that it's ignored for all non-export operations.2.
Alternative proposal - _metadata
Alternatively, the defaultSettings read-only property could be returned as metadata. I prefer not to follow this model, as it seems effectively the same, but with an additional level of nesting:
port:
- 22
addressfamily: any
listenaddress:
- 0.0.0.0:22
- '[::]:22'
logingracetime: 120
x11displayoffset: 10
maxauthtries: 6
syslogfacility: LOCAL0
authorizedkeysfile:
- .ssh/authorized_keys
_metadata:
defaultSettings:
- port
- addressfamily
- listenaddress
- logingracetime
- x11displayoffset
- maxauthtriesI would prefer that we reserve using _metadata for things that can't effectively be modeled by the resource, or provide context external to it (such as the current security context). In this case, which settings are provided as defaults by SSHD is knowable and describable from the resource surface.
I think we would still need to define the write-only exportDefaults property. Similarly, we could nest it under the _metadata field, but I'm not sure whether this improves the user experience.
Proposed technical implementation details (optional)
No response
Footnotes
-
I'm only showing the example output for the
getoperation here, but I would expect that thedefaultSettingsread-only property would also be populated in the actual state fortestand thebefore/afterstate forset- this would also help distinguish changes where a default setting was explicitly defined to the same or a different value. ↩ -
In the future, we may want to introduce a keyword to our schema vocabulary that limits which operations a property is valid for, but I don't think it's currently necessary. Having that keyword could improve documentation/validation, but for now I think annotating the usage in documentation is sufficient. ↩
Metadata
Metadata
Assignees
Labels
Type
Projects
Status