Skip to content

Proposal: Handling default settings for SSHD configuration resource #1030

@michaeltlombardi

Description

@michaeltlombardi

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: false is passed in via _metadata, get returns the subset of settings from SSHD -T that are not defaults
  • if filepath: <filepath> is passed in via _metadata, get runs SSHD -T -f <filepath>

The differing behavior for input/no-input in the get operation here is a break from prior design, user expectation, and integration with higher order tooling. Typically, get operations return the full configurable state for a resource instance. This filtering makes more sense to me for the export operation. 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, filepath is a non-required key property - I would expect a configuration document containing any two instances of this resource with the same filepath (or filepath not 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 defaultSettings property as an array of property names.
  • Indicate whether the resource should explicitly export default settings with a write-only exportDefaults property.

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 get
port:
- 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
- maxauthtries

Behavior for export

When defining the resource for the export operation, the exportDefaults write-only property changes the result object:

  • Without the exportDefaults property defined, the output includes only the explicitly set properties:

    sshdconfig export
    syslogfacility: LOCAL0
    authorizedkeysfile:
    - .ssh/authorized_keys
  • With exportDefaults defined as true, the export operation returns the effective configuration - when used in set, 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 defaultSettings property - because for the exported instance, none of the settings are default.

    The documentation for the exportDefaults write-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
  - maxauthtries

I 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

  1. I'm only showing the example output for the get operation here, but I would expect that the defaultSettings read-only property would also be populated in the actual state for test and the before/after state for set - this would also help distinguish changes where a default setting was explicitly defined to the same or a different value.

  2. 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

No one assigned

    Type

    No type

    Projects

    Status

    In Progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions