Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] issuegen: detect util-linux RPM version, set output directory appropriately #40

Closed
wants to merge 2 commits into from

Conversation

rfairley
Copy link
Contributor

Builds on #36, with more general tidyups to the issuegen code. This is prep for more general work for #7 .

@rfairley rfairley force-pushed the rfairley-issuegen-tidy branch 2 times, most recently from 23a8497 to c2eb4b8 Compare April 20, 2020 18:01
rfairley pushed a commit to rfairley/console-login-helper-messages that referenced this pull request Apr 20, 2020
For the same reason as in coreos#39
(copying the phrasing below):

With the `staged` file shared, there would be potential for two or
more processes executing `motdgen` to write to it resulting in
corrupted output, or the error in the `cat` command due to missing
file reported in coreos#35 (comment). Currently, this is not a problem with
motdgen, but could be if `motdgen` were invoked by something like the
udev rules that invoke `issuegen`.

Instead, write the intermediate output to a variable before writing
to the final output file. This ensures only valid output is written
to the issue file shown to the terminal.

Additionally, perform code tidyups similar to those done for
`issuegen` in coreos#40.
@rfairley rfairley force-pushed the rfairley-issuegen-tidy branch from c2eb4b8 to 2b5da38 Compare April 20, 2020 18:24
@dustymabe
Copy link
Member

will review this one more thoroughly when we get #39 merged and this is rebased

@rfairley rfairley force-pushed the rfairley-issuegen-tidy branch from 2b5da38 to 3f4e49a Compare April 20, 2020 21:56
;;
esac

# TODO: it would be nice to have /run/issue.d be an official directory,
# see https://github.com/karelzak/util-linux/commit/1fc82a1360305f696dc1be6105c9c56a9ea03f52#commitcomment-27949895
# until then, $GENERATED_ISSUE writes to the privately scoped directory (not in /run/issue.d)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In particular, #7 is tracking this comment - no longer need to mention in the source.

@rfairley rfairley force-pushed the rfairley-issuegen-tidy branch from 3f4e49a to 81458f2 Compare April 20, 2020 22:29
ISSUE_SNIPPETS_PATH=${PKG_NAME}/issue.d
ETC_SNIPPETS="/etc/${ISSUE_SNIPPETS_PATH}"
RUN_SNIPPETS="/run/${ISSUE_SNIPPETS_PATH}"
USR_LIB_SNIPPETS="/usr/lib/${ISSUE_SNIPPETS_PATH}"
Copy link
Contributor Author

@rfairley rfairley Apr 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking the variable names should not need to distinguish the private/public path, at least for now, since for issuegen all snippets are written into the "private" directories. Previously, ISSUE_DIR_PUBLIC was unused. The *_SNIPPETS variables will just refer to the snippet paths that will get read in order to create ${generated_file}.

For #7, we may allow a choice of using the public or private locations for the snippet locations by invoking e.g. issuegen or issuegen --legacy respectively from the console-login-helper-messages-issuegen.service unit (this choice would be needed for systems that have util-linux version under 2.35 - e.g. RHCOS). We would probably try to split the ssh, udev, and generated issue parts up and have SSH_KEY_OUTDIR and UDEV_IF_OUTDIR set to either /run/issue.d (public) or /run/console-login-helper-messages/issue.d (private - i.e. the RUN_SNIPPETS variable). The private locations would be used for the *_OUTDIR variables if --legacy was passed. However more discussion can be done on this in #7. In any case, the *_SNIPPETS locations should be consumed only when creating ${generated_file} - the *_SNIPPETS variables shouldn't need to change after this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could either use a config file (like a file in /etc/console-login-helper-messages/foo.conf) to set the paths to output to or we could detect the version of util-linux and switch based on that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

though would we still want to use a private directory for all the snippets and then just write out generated_file to the public directory like we do for motdgen in #44

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 a config file would be good at some point. A specfile would make the choice on the output paths set in /etc/console-login-helper-messages/foo.conf, based on the util-linux version.

I'm thinking if a config file is added, we'd want to support an extensible config file format - which would allow on/off configuration for each piece of information (udev interfaces, ssh keys, etc) (#15), and whether the snippets are output in the issue, motd, or other. I've opened this to discuss #45.

For now, going with having issuegen check the util-linux version and set SSH_KEY_OUTDIR, UDEV_IF_OUTDIR, and generated_file appropriately seems simplest - this could be default behaviour if a config path was not specified if we added a config file. Will update this PR with the check on the util-linux version and setting the path shortly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now updated with the version check - kept so that the check would only make the switch automatically for RPM-based distributions for now.

rfairley pushed a commit to rfairley/console-login-helper-messages that referenced this pull request Apr 20, 2020
For the same reason as in coreos#39
(copying the phrasing below):

With the `staged` file shared, there would be potential for two or
more processes executing `motdgen` to write to it resulting in
corrupted output, or the error in the `cat` command due to missing
file reported in coreos#35 (comment). Currently, this is not a problem with
motdgen, but could be if `motdgen` were invoked by something like the
udev rules that invoke `issuegen`.

Instead, write the intermediate output to a variable before writing
to the final output file. This ensures only valid output is written
to the issue file shown to the terminal.

Additionally, perform code tidyups similar to those done for
`issuegen` in coreos#40.
rfairley pushed a commit to rfairley/console-login-helper-messages that referenced this pull request Apr 20, 2020
For the same reason as in coreos#39
(copying the phrasing below):

With the `staged` file shared, there would be potential for two or
more processes executing `motdgen` to write to it resulting in
corrupted output, or the error in the `cat` command due to missing
file reported in coreos#35 (comment). Currently, this is not a problem with
motdgen, but could be if `motdgen` were invoked by something like the
udev rules that invoke `issuegen`.

Instead, write the intermediate output to a variable before writing
to the final output file. This ensures only valid output is written
to the issue file shown to the terminal.

Additionally, perform code tidyups similar to those done for
`issuegen` in coreos#40.
@rfairley rfairley force-pushed the rfairley-issuegen-tidy branch from 81458f2 to b6196b8 Compare April 23, 2020 02:20
@rfairley rfairley changed the title issuegen: tidyups to code issuegen: tidyups to code, detect util-linux RPM version Apr 23, 2020
Clean up code by minimizing the number of variables and shortening
the variable names. Remove unneeded comments, and add a few more
clarifying comments.

Separate code into clearer blocks for different operations
(generating SSH key information, udev data, and the final output
issue file).
rfairley pushed a commit to rfairley/console-login-helper-messages that referenced this pull request May 18, 2020
For the same reason as in coreos#39
(copying the phrasing below):

With the `staged` file shared, there would be potential for two or
more processes executing `motdgen` to write to it resulting in
corrupted output, or the error in the `cat` command due to missing
file reported in coreos#35 (comment). Currently, this is not a problem with
motdgen, but could be if `motdgen` were invoked by something like the
udev rules that invoke `issuegen`.

Instead, write the intermediate output to a variable before writing
to the final output file. This ensures only valid output is written
to the issue file shown to the terminal.

Additionally, perform code tidyups similar to those done for
`issuegen` in coreos#40.
If the util-linux version installed is greater than or equal to
2.35, when support for /run/issue.d was added, set the the output
paths so that /run/issue.d is utilized.

The version check for util-linux is done by using `rpm` to check
the version of an installed util-linux RPM package. For
non-RPM-based systems, the output paths will take a default
value of the private directory location /run/console-login-helper-messages/issue.d.
`rpm` is chosen to perform the check as the only kown consumers of
console-login-helper-messages are RPM-based distributions, however
support could always later be added for Debian-based or other
Linux distributions.
@rfairley rfairley force-pushed the rfairley-issuegen-tidy branch from b6196b8 to abfced0 Compare May 19, 2020 00:11
@rfairley rfairley changed the title issuegen: tidyups to code, detect util-linux RPM version [WIP] issuegen: detect util-linux RPM version, set output directory appropriately May 19, 2020
@rfairley
Copy link
Contributor Author

For now, putting this PR on hold and making the PR about the util-linux version check rather than just the issuegen code tidyups, due to #7 (comment).

Bringing forward the same issuegen tidyups in #43 - let's do the review there

rfairley pushed a commit to rfairley/console-login-helper-messages that referenced this pull request May 22, 2020
For the same reason as in coreos#39
(copying the phrasing below):

With the `staged` file shared, there would be potential for two or
more processes executing `motdgen` to write to it resulting in
corrupted output, or the error in the `cat` command due to missing
file reported in coreos#35 (comment). Currently, this is not a problem with
motdgen, but could be if `motdgen` were invoked by something like the
udev rules that invoke `issuegen`.

Instead, write the intermediate output to a variable before writing
to the final output file. This ensures only valid output is written
to the issue file shown to the terminal.

Additionally, perform code tidyups similar to those done for
`issuegen` in coreos#40.
rfairley pushed a commit to rfairley/console-login-helper-messages that referenced this pull request Jul 1, 2020
For the same reason as in coreos#39
(copying the phrasing below):

With the `staged` file shared, there would be potential for two or
more processes executing `motdgen` to write to it resulting in
corrupted output, or the error in the `cat` command due to missing
file reported in coreos#35 (comment). Currently, this is not a problem with
motdgen, but could be if `motdgen` were invoked by something like the
udev rules that invoke `issuegen`.

Instead, write the intermediate output to a variable before writing
to the final output file. This ensures only valid output is written
to the issue file shown to the terminal.

Additionally, perform code tidyups similar to those done for
`issuegen` in coreos#40.
rfairley pushed a commit to rfairley/console-login-helper-messages that referenced this pull request Jul 1, 2020
With the `staged` file shared, there would be potential for two or
more processes executing `motdgen` to write to it resulting in
corrupted output, or the error in the `cat` command due to missing
file reported in coreos#35 (comment). Currently, this is not a problem with
motdgen, but could be if `motdgen` were invoked by something like the
udev rules that invoke `issuegen`. A bug reported in `issuegen` for
this reason is: coreos#35

Instead, write the intermediate output to a unique tempfile and mv the
tempfile to the final output location. If the final output is on the
same filesystem as the tempfile, this operation should be atomic. This
ensures only valid output is written to the issue file shown to the
terminal.

Additionally, perform code tidyups similar to those done for
`issuegen` in coreos#40.
rfairley pushed a commit to rfairley/console-login-helper-messages that referenced this pull request Jul 2, 2020
With the `staged` file shared, there would be potential for two or
more processes executing `motdgen` to write to it resulting in
corrupted output, or the error in the `cat` command due to missing
file reported in coreos#35 (comment). Currently, this is not a problem with
motdgen, but could be if `motdgen` were invoked by something like the
udev rules that invoke `issuegen`. A bug reported in `issuegen` for
this reason is: coreos#35

Instead, write the intermediate output to a unique tempfile and mv the
tempfile to the final output location. If the final output is on the
same filesystem as the tempfile, this operation should be atomic. This
ensures only valid output is written to the issue file shown to the
terminal.

Additionally, perform code tidyups similar to those done for
`issuegen` in coreos#40.
rfairley pushed a commit to rfairley/console-login-helper-messages that referenced this pull request Jul 2, 2020
For the same reason as in coreos#39
(copying the phrasing below):

With the `staged` file shared, there would be potential for two or
more processes executing `motdgen` to write to it resulting in
corrupted output, or the error in the `cat` command due to missing
file reported in coreos#35 (comment). Currently, this is not a problem with
motdgen, but could be if `motdgen` were invoked by something like the
udev rules that invoke `issuegen`.

Instead, write the intermediate output to a variable before writing
to the final output file. This ensures only valid output is written
to the issue file shown to the terminal.

Additionally, perform code tidyups similar to those done for
`issuegen` in coreos#40.
rfairley pushed a commit to rfairley/console-login-helper-messages that referenced this pull request Jul 3, 2020
With the `staged` file shared, there would be potential for two or
more processes executing `motdgen` to write to it resulting in
corrupted output, or the error in the `cat` command due to missing
file reported in coreos#35 (comment). Currently, this is not a problem with
motdgen, but could be if `motdgen` were invoked by something like the
udev rules that invoke `issuegen`. A bug reported in `issuegen` for
this reason is: coreos#35

Instead, write the intermediate output to a unique tempfile and mv the
tempfile to the final output location. If the final output is on the
same filesystem as the tempfile, this operation should be atomic. This
ensures only valid output is written to the issue file shown to the
terminal.

Additionally, perform code tidyups similar to those done for
`issuegen` in coreos#40.
rfairley pushed a commit to rfairley/console-login-helper-messages that referenced this pull request Jul 3, 2020
With the `staged` file shared, there would be potential for two or
more processes executing `motdgen` to write to it resulting in
corrupted output, or the error in the `cat` command due to missing
file reported in coreos#35 (comment). Currently, this is not a problem with
motdgen, but could be if `motdgen` were invoked by something like the
udev rules that invoke `issuegen`. A bug reported in `issuegen` for
this reason is: coreos#35

Instead, write the intermediate output to a unique tempfile and mv the
tempfile to the final output location. If the final output is on the
same filesystem as the tempfile, this operation should be atomic. This
ensures only valid output is written to the issue file shown to the
terminal.

Additionally, perform code tidyups similar to those done for
`issuegen` in coreos#40.
@rfairley rfairley closed this Jul 3, 2020
@rfairley rfairley deleted the rfairley-issuegen-tidy branch July 3, 2020 06:48
@rfairley rfairley restored the rfairley-issuegen-tidy branch July 3, 2020 06:51
@rfairley rfairley reopened this Jul 3, 2020
rfairley pushed a commit to rfairley/console-login-helper-messages that referenced this pull request Jul 5, 2020
With the `staged` file shared, there would be potential for two or
more processes executing `motdgen` to write to it resulting in
corrupted output, or the error in the `cat` command due to missing
file reported in coreos#35 (comment). Currently, this is not a problem with
motdgen, but could be if `motdgen` were invoked by something like the
udev rules that invoke `issuegen`. A bug reported in `issuegen` for
this reason is: coreos#35

Instead, write the intermediate output to a unique tempfile and mv the
tempfile to the final output location. If the final output is on the
same filesystem as the tempfile, this operation should be atomic. This
ensures only valid output is written to the issue file shown to the
terminal.

Additionally, perform code tidyups similar to those done for
`issuegen` in coreos#40.
rfairley pushed a commit to rfairley/console-login-helper-messages that referenced this pull request Jul 5, 2020
With the `staged` file shared, there would be potential for two or
more processes executing `motdgen` to write to it resulting in
corrupted output, or the error in the `cat` command due to missing
file reported in coreos#35 (comment). Currently, this is not a problem with
motdgen, but could be if `motdgen` were invoked by something like the
udev rules that invoke `issuegen`. A bug reported in `issuegen` for
this reason is: coreos#35

Instead, write the intermediate output to a unique tempfile and mv the
tempfile to the final output location. If the final output is on the
same filesystem as the tempfile, this operation should be atomic. This
ensures only valid output is written to the issue file shown to the
terminal.

Additionally, perform code tidyups similar to those done for
`issuegen` in coreos#40.
rfairley pushed a commit to rfairley/console-login-helper-messages that referenced this pull request Jul 6, 2020
With the `staged` file shared, there would be potential for two or
more processes executing `motdgen` to write to it resulting in
corrupted output, or the error in the `cat` command due to missing
file reported in coreos#35 (comment). Currently, this is not a problem with
motdgen, but could be if `motdgen` were invoked by something like the
udev rules that invoke `issuegen`. A bug reported in `issuegen` for
this reason is: coreos#35

Instead, write the intermediate output to a unique tempfile and mv the
tempfile to the final output location. If the final output is on the
same filesystem as the tempfile, this operation should be atomic. This
ensures only valid output is written to the issue file shown to the
terminal.

Additionally, perform code tidyups similar to those done for
`issuegen` in coreos#40.
rfairley pushed a commit to rfairley/console-login-helper-messages that referenced this pull request Jul 6, 2020
With the `staged` file shared, there would be potential for two or
more processes executing `motdgen` to write to it resulting in
corrupted output, or the error in the `cat` command due to missing
file reported in coreos#35 (comment). Currently, this is not a problem with
motdgen, but could be if `motdgen` were invoked by something like the
udev rules that invoke `issuegen`. A bug reported in `issuegen` for
this reason is: coreos#35

Instead, write the intermediate output to a unique tempfile and mv the
tempfile to the final output location. If the final output is on the
same filesystem as the tempfile, this operation should be atomic. This
ensures only valid output is written to the issue file shown to the
terminal.

Additionally, perform code tidyups similar to those done for
`issuegen` in coreos#40.
rfairley pushed a commit to rfairley/console-login-helper-messages that referenced this pull request Jul 8, 2020
With the `staged` file shared, there would be potential for two or
more processes executing `motdgen` to write to it resulting in
corrupted output, or the error in the `cat` command due to missing
file reported in coreos#35 (comment). Currently, this is not a problem with
motdgen, but could be if `motdgen` were invoked by something like the
udev rules that invoke `issuegen`. A bug reported in `issuegen` for
this reason is: coreos#35

Instead, write the intermediate output to a unique tempfile and mv the
tempfile to the final output location. If the final output is on the
same filesystem as the tempfile, this operation should be atomic. This
ensures only valid output is written to the issue file shown to the
terminal.

Additionally, perform code tidyups similar to those done for
`issuegen` in coreos#40.
@kelvinfan001
Copy link
Member

The work in this PR is continued in #76. I created the new PR since the repo changed quite a bit since, and it would be quite a pain to resolve all the conflicts. Thanks Robert for the helpful comments.

@kelvinfan001
Copy link
Member

Closing for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants