coreos / butane

Butane translates human-readable Butane Configs into machine-readable Ignition Configs.
https://coreos.github.io/butane/
Apache License 2.0
255 stars 70 forks source link

Systemd unit validation issue. #492

Open martafolf opened 1 year ago

martafolf commented 1 year ago

Creating systemd objects like targets can cause confusing errors where enable is true but an install section is missing under --strict checking.

Take the following example butane:

variant: fcos
version: 1.5.0

systemd:
    units:
        - name: test.target
          enabled: true
          contents: |
              [Unit]
              Description=Test Target
              Requires=multi-user.taget
              After=multi-user.target
              AllowIsolate=yes
storage: 
    links:
        - target: /etc/systemd/system/test.target
          path: /etc/systemd/system/default.target
          overwrite: true

In this file we create a new test.target and then via the symlink from default.target we specify it as the system default target. (Would there be interest in ignition/butane handling this case natively? I.e. default: true for a target configuration)

Because of it becoming the default target, an [Install] section is not required as there are no WantedBy's to fulfill, or any other option to add for this to work.

In this configuration it seems the right setup to have it enabled, the symlink seems to yeld odd failures if the target is not enabled too at the ignition step, despite the unit file being placed in the same location, although I suspect that is a different issue and I am in the process of debugging that further.

That aside, the problem is evident when creating an ignition file with the --strict option passed:

# butane --strict < test.bu
warning at $.systemd.units.0.contents, line 8 col 21: unit "test.target" is enabled, but has no install section so enable does nothing
Config produced warnings and --strict was specified

It seems that by not containing a valid [Install] section the check fails, this makes sense for service files or other units, however for targets this is not necessarily a requirement.

Let me know if I've misunderstood this property, or if you need any further information from me, thank you. 😄