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

symlink local_secret_token.rb to /etc/foreman #2143

Merged
merged 1 commit into from
May 16, 2018

Conversation

sean797
Copy link
Member

@sean797 sean797 commented Jan 30, 2018

Currently we have:

[root@centos7-foreman ~]# ls -l /etc/foreman
total 20
-rw-r-----. 1 root foreman  684 Jan 16 16:27 database.yml
-rw-r-----. 1 root foreman  450 Jan 15 22:22 encryption_key.rb
-rw-r--r--. 1 root root     691 Nov 29 07:12 foreman-debug.conf
-rw-r--r--. 1 root root    2564 Nov 29 07:12 logging.yaml
drwxr-xr-x. 2 root root      72 Jan 16 16:28 plugins
-rw-r-----. 1 root foreman 1215 Jan 17 13:04 settings.yaml

It'd would be nice to also have local_secret_token.rb

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

It does make sense to me, but should we also move an existing local_secret_token.rb to /etc/foreman? Should the current ghost in the datadir be removed? I'm not sure how this can be handled safely though.

@sean797
Copy link
Member Author

sean797 commented Feb 12, 2018

Thanks @ekohl, I've added a migration

Should the current ghost in the datadir be removed?

I don't think so, encryption_key.rb still has ghost

@sean797
Copy link
Member Author

sean797 commented Feb 21, 2018

rebased

@@ -1144,6 +1145,17 @@ if [ ! -f %{_datadir}/%{name}/config/initializers/local_secret_token.rb ]; then
chgrp foreman %{_datadir}/%{name}/config/initializers/local_secret_token.rb
%{foreman_rake} security:generate_token >/dev/null 2>&1 || :
chmod 0640 %{_datadir}/%{name}/config/initializers/local_secret_token.rb
mv %{_datadir}/%{name}/config/initializers/local_secret_token.rb %{_sysconfdir}/%{name}/
Copy link
Member

Choose a reason for hiding this comment

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

If we ensure the symlink is in place before running the token generation, would that also ensure it's generated in the right place? Ideally that means we can ship a symlink inside the package. We'd need to ensure the current token isn't overwritten though.

@sean797 sean797 force-pushed the symlink-cookies branch 2 times, most recently from 85a764c to 65cee41 Compare February 21, 2018 16:31
@sean797
Copy link
Member Author

sean797 commented Feb 21, 2018

hows that @ekohl ?

@ekohl ekohl added the RPM label Feb 22, 2018
@ekohl
Copy link
Member

ekohl commented Apr 5, 2018

Apologies for the long delay. In b0bc45f I implemented a similar change. By going the %pre route, you can assume the state is correct in %install and it greatly simplifies things. On the other hand, I don't know if the rake task will follow the symlink. Probably not.

Below is my explicit thought process so you can check if I've missed anything.

  • The ln -s in the first if block should be removed because the rake task would overwrite it (assumption, but safe and simplifies things for later).
  • A separate if block that moves it to /etc. This would handle the existing installations as well as just after the generation.
  • Another if block that creates the symlink.

So:

if [ ! -e %{_datadir}/%{name}/config/initializers/local_secret_token.rb ] ; then
  touch %{_datadir}/%{name}/config/initializers/local_secret_token.rb
  chmod 0660 %{_datadir}/%{name}/config/initializers/local_secret_token.rb
  chgrp foreman %{_datadir}/%{name}/config/initializers/local_secret_token.rb
  %{foreman_rake} security:generate_token >/dev/null 2>&1 || :
  chmod 0640 %{_datadir}/%{name}/config/initializers/local_secret_token.rb
fi
if [ -f %{_datadir}/%{name}/config/initializers/local_secret_token.rb ] ; then
  mv %{_datadir}/%{name}/config/initializers/local_secret_token.rb %{_sysconfdir}/%{name}/
fi
if [ ! -e %{_datadir}/%{name}/config/initializers/local_secret_token.rb -a \
    -e %{_sysconfdir}/%{name}/local_secret_token.rb ]; then
  ln -s %{_sysconfdir}/%{name}/local_secret_token.rb %{_datadir}/%{name}/config/initializers/
fi

@ekohl
Copy link
Member

ekohl commented Apr 5, 2018

https://projects.theforeman.org/issues/16508 is also interesting to consider in this context but I'd be happy with just implementing this now.

@sean797
Copy link
Member Author

sean797 commented Apr 23, 2018

Yup - thanks does make sense, thanks @ekohl 👍

touch %{_datadir}/%{name}/config/initializers/local_secret_token.rb
chmod 0660 %{_datadir}/%{name}/config/initializers/local_secret_token.rb
chgrp foreman %{_datadir}/%{name}/config/initializers/local_secret_token.rb
%{foreman_rake} security:generate_token >/dev/null 2>&1 || :
chmod 0640 %{_datadir}/%{name}/config/initializers/local_secret_token.rb
fi
if [ -f %{_datadir}/%{name}/config/initializers/local_secret_token.rb ] ; then
Copy link
Member

Choose a reason for hiding this comment

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

In 796febe I fixed an oversight I had: -f dereferences symlinks.

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

Could you have a look at the -f comment?

@sean797 sean797 force-pushed the symlink-cookies branch from 90e13b3 to cdc97d0 Compare May 14, 2018 11:35
@sean797
Copy link
Member Author

sean797 commented May 14, 2018

Thanks for the reminder, updated..

@evgeni
Copy link
Member

evgeni commented May 14, 2018

So I think the only thing I don't like here is that the token is still generated in datadir and then moved to sysconfdir, but such is life.

ACK

@ekohl
Copy link
Member

ekohl commented May 14, 2018

So I think the only thing I don't like here is that the token is still generated in datadir and then moved to sysconfdir, but such is life.

theforeman/foreman#5553 should make that easier.

@ekohl ekohl merged commit 5970025 into theforeman:rpm/develop May 16, 2018
@ekohl
Copy link
Member

ekohl commented May 16, 2018

Thanks!

@ekohl
Copy link
Member

ekohl commented May 17, 2018

Looks like this caused an issue with building. From http://koji.katello.org/kojifiles/work/tasks/8811/98811/build.log:

LoadError: cannot load such file -- /builddir/build/BUILD/katello-3.7.0/usr/share/foreman/config/initializers/local_secret_token.rb

@sean797 sean797 deleted the symlink-cookies branch May 17, 2018 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants