Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Don't Use PW in ENV vars and default SSL on #39

Merged
merged 13 commits into from
Jul 13, 2018
Merged

Conversation

fxdgear
Copy link
Contributor

@fxdgear fxdgear commented May 8, 2018

New Description to account for changes in direction during the life of this PR and feedback received.

  1. Don't use ENV vars to specify passwords for running containers
  2. Setup script and yml file will
  • generate an ELASTIC_PASSWORD if one is not provided by the user at script execution time.
  • generate certs for security
  • generate keystores to store passwords securely
  1. Use docker secrets (aka a volume mount in compose) to securely include the sensitive info (keystores, certs, etc) in containers at container run time.
  2. Each configuration file is now included in the config directory and no longer are configs managed via env vars.
  • this makes it easier to see what the configs are
  • make changes to them for personal use or experimentation
  • configs pull sensitive information from keystores previously generated.
  1. Security is enabled by default and communication between services is done over ssl/tls.
  • with the exception of kibana. Kibana runs on port 5601 without ssl enabled. This is to avoid the hoops of navigating to a website with an untrusted (self signed) cert. But communication between Kibana and Elasticsearch are secured and use SSL.

@fxdgear fxdgear changed the title [WIP] Don't Use PW in ENV vars [WIP] Don't Use PW in ENV vars and default SSL on May 8, 2018
hosts: ['elasticsearch:9200']
protocol: "https"
username: elastic
# Read PW from auditbeat.keystore
Copy link

Choose a reason for hiding this comment

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

Nitpick: apm.keystore

hosts: ['elasticsearch:9200']
protocol: "https"
username: elastic
# Read PW from auditbeat.keystore
Copy link

Choose a reason for hiding this comment

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

Ok, this must be a copy paste issue :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hah yeah it is I'll fix.

reload.enabled: false

processors:
- add_cloud_metadata:
Copy link

Choose a reason for hiding this comment

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

Shouldn't this be add_docker_metadata? Here and in the 3 other Beats configs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh? Quite possibly. I just copied out the config from each container as it ran in the master branch.

I wasn’t checking for correctness.

But I suppose this exercise is a good one given that we can now analyze more easily the config for each service.

Copy link

Choose a reason for hiding this comment

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

Ah, I didn't check that. I've created #40 to keep track of this — no point in adding that to this PR as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1

Copy link
Contributor

@elasticdog elasticdog left a comment

Choose a reason for hiding this comment

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

This all makes sense to me and looks much cleaner! Loving the direction.

Beyond @jarpy's make on Windows concern, my only real comment is that checking in static public/private keys (even as an example) is a bit of a fishy smell to me. I could see where someone might accidentally run something production-y using those...could we instead generate them as part of the initial setup step?

@fxdgear
Copy link
Contributor Author

fxdgear commented May 9, 2018

@elasticdog Make is for Linux/Mac people. Windows users can use the multiple -f in docker compose.

I’ll upstate to dynamically create keystores and certs.

Thanks for the feedback.

@jarpy
Copy link
Contributor

jarpy commented May 9, 2018

There's something nasty happening with file permissions. When I bring up the stack I see this:

heartbeat            | Exiting: error loading config file: config file ("heartbeat.yml") can only be writable by the owner but the permissions are "-rw-rw-r--" (to fix the permissions use: 'chmod go-w /usr/share/heartbeat/heartbeat.yml')
heartbeat exited with code 1
metricbeat           | Exiting: error loading config file: config file ("metricbeat.yml") can only be writable by the owner but the permissions are "-rw-rw-r--" (to fix the permissions use: 'chmod go-w /usr/share/metricbeat/metricbeat.yml')
metricbeat exited with code 1
packetbeat           | Exiting: error loading config file: config file ("packetbeat.yml") can only be writable by the owner but the permissions are "-rw-rw-r--" (to fix the permissions use: 'chmod go-w /usr/share/packetbeat/packetbeat.yml')
auditbeat            | Exiting: error loading config file: config file ("auditbeat.yml") must be owned by the beat user (uid=0) or root
packetbeat exited with code 1
filebeat             | Exiting: error loading config file: config file ("filebeat.yml") can only be writable by the owner but the permissions are "-rw-rw-r--" (to fix the permissions use: 'chmod go-w /usr/share/filebeat/filebeat.yml')
filebeat exited with code 1
auditbeat exited with code 1
apm_server           | Exiting: error loading config file: config file ("apm-server.yml") can only be writable by the owner but the permissions are "-rw-rw-r--" (to fix the permissions use: 'chmod go-w /usr/share/apm-server/apm-server.yml')

Same behaviour on Windows and Linux.

@jarpy
Copy link
Contributor

jarpy commented May 9, 2018

I'm in two minds about running Kibana on HTTPS. It means that the first thing a brand new user sees is an error page with the word "unsafe" in it. We know that's just a self-signed cert, but it doesn't give that "it just works" feeling.

@fxdgear
Copy link
Contributor Author

fxdgear commented May 9, 2018

@jarpy I'm happy you ran into the permissions issue. I kinda thought it might happen. But wasn't sure. I'll update. thank you

@fxdgear fxdgear force-pushed the nick/dont_use_pw_in_env branch 2 times, most recently from d0fb0d2 to 1a1f656 Compare June 22, 2018 18:54
* upgrade docker-compose file version
* upgrade elasticstack TAG
* use secrets instead of PW in ENV vars
    * Make it easy to use secrets
    * Don't teach people to use passwords in ENV vars
    * just as easy to use a docker secret as it is to use a bind mounted volume
* adding setup.yml to create
  1. passwords
  2. keystores
  3. certs

adding health checks

update the readme

turn off ssl for kibana endbpoint to avoid confusion for new users
@fxdgear
Copy link
Contributor Author

fxdgear commented Jul 2, 2018

@elastic/infra if anyone would like to review this PR I'm happy to answer any questions. i think it's ready to go now for real world use.

@fxdgear fxdgear changed the title [WIP] Don't Use PW in ENV vars and default SSL on Don't Use PW in ENV vars and default SSL on Jul 2, 2018
@tvernum
Copy link

tvernum commented Jul 3, 2018

Keystores are pre-configured with the "changeme" password

Assuming I understand this correctly, can we please not do this.
We went to a lot of trouble to get rid of default passwords from ES, please don't add them back in via docker.

Ping: @elastic/es-security

@fxdgear
Copy link
Contributor Author

fxdgear commented Jul 3, 2018

@tvernum

What are you trying to understand. I'm creating a keystore and then adding the password "changeme" to it.

If you're wanting to get away from the password "changeme" I can default it to something else.

the other option is I can use an automatically generated password and output it in the setup script after everything is done. Something like:

The elastic password is: blahblahblah

Will that work?

EDIT: @tvernum also I realized after re-reading my PR description it needs to be changed to reflect the fact that the keystores (and any senstiive) info is no longer included like I had originally done in this PR.

Keystores and certs are now generated using the setup.sh script in the setup.yml docker-compose file. This allows for every single instance of this project when run to be using unique sensitive data.

@tvernum
Copy link

tvernum commented Jul 4, 2018

@fxdgear Sorry, I had forgotten that stack-docker has historically had a pre-configured password ( 😢 😭 🤢 😡 )

I would truly love if we never shipped anything that had any preconfigured password in it. Even for things that are intended to be examples rather than production ready - users take what we provide as a gold standard and do likewise.

If it's possible for the setup process to ask for a password, or generate a password that would be a wonderful step forwards.

Also updated to echo the pw for the user when the script finishes.
@fxdgear
Copy link
Contributor Author

fxdgear commented Jul 5, 2018

@tvernum Does the latest commit work for you?
e1306b4

thanks for taking the time to review this!

Copy link

@Crazybus Crazybus left a comment

Choose a reason for hiding this comment

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

I tried to run stack-docker blindly following the projects readme (as I would expect our users to do). I ran into a couple of issues which can be quickly fixed up.

README.md Outdated

Point a browser at [`http://localhost:5601`](http://localhost:5601) to see the results.
> *NOTE*: Elasticsearch is now setup with self-signed certs.

Log in with `elastic` / `changeme`.
Copy link

Choose a reason for hiding this comment

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

This should be updated to explain that the autogenerated password needs to be used if you don't set it yourself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1 thanks will do.

Makefile Outdated
centos:7 "/usr/local/bin/setup-permissions.sh"

setup_users:
docker-compose run --no-deps -e ELASTIC_PASSWORD=changeme elasticsearch /usr/local/bin/setup-users.sh
Copy link

Choose a reason for hiding this comment

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

This hardcoded password doesn't work anymore here. This will need to use the autogenerted password that you have now added.

Makefile Outdated
docker-compose run --no-deps -e ELASTIC_PASSWORD=changeme heartbeat /usr/local/bin/setup-beat.sh heartbeat

setup_metricbeat:
docker-compose run --no-deps -e ELASTIC_PASSWORD=changeme metricbeat /usr/local/bin/setup-beat.sh metricbeat
Copy link

Choose a reason for hiding this comment

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

I didn't dive into it but when I try to run make setup_metricbeat with the ELASTIC_PASSWORD updated to my autogenerated one I'm getting Read-only file system errors.

chmod: changing permissions of '/usr/share/metricbeat/metricbeat.yml': Read-only file system

@fxdgear
Copy link
Contributor Author

fxdgear commented Jul 6, 2018

@Crazybus 💥 thanks for the feedback. I forgot that I modified the Makefile. I'm gonna set that back to it's normal thing cause I put all the setup in a docker container. There's no need to use the make file anymore as a general user.

update docs on readme for how to use and get the elastic password
@fxdgear
Copy link
Contributor Author

fxdgear commented Jul 6, 2018

@jarpy @tvernum @xeraa @Crazybus

You all have commented on this PR at some point. I'd like to invite you to review it again.

I feel like I've addressed everyones comments and concerns, and would like to get this "done" with so it's not something I have lingering anymore :)

Thanks for all your assistance with this.

@jarpy
Copy link
Contributor

jarpy commented Jul 9, 2018

I think this breaks on Windows because it depends on the Docker Unix socket.

λ  docker-compose -f setup.yml up
WARNING: The PWD variable is not set. Defaulting to a blank string.
Creating stack-docker_setup_1 ... error

ERROR: for stack-docker_setup_1  Cannot create container for service setup: b'Mount denied:\nThe source path "\\\\var\\\\run\\\\docker.sock:/var/run/docker.sock"\nis not a valid Windows path'

ERROR: for setup  Cannot create container for service setup: b'Mount denied:\nThe source path "\\\\var\\\\run\\\\docker.sock:/var/run/docker.sock"\nis not a valid Windows path'
ERROR: Encountered errors while bringing up the project.

@fxdgear
Copy link
Contributor Author

fxdgear commented Jul 9, 2018

@jarpy ahh thanks for this. you have to specify some env vars for a windows user and I forgot to put those in the read me. I'll add thanks. :)

Makefile Outdated
@@ -28,3 +28,4 @@ $(TARGETS:%=%-checkout):

$(TARGETS:%=%-clean):
rm -rf stack/$(@:%-clean=%)
Copy link

Choose a reason for hiding this comment

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

Can we make sure make clean also removes the keystores? Took me a while to figure out why this was causing me problems when trying to spin up a fresh cluster after doing a make clean and a delete all my docker data with fire

* remove keystores
* do proper docker-compose down
* remove volumes and networks

make it fresh
@fxdgear
Copy link
Contributor Author

fxdgear commented Jul 9, 2018

@Crazybus I made the makefile a bit more exhaustive wrt to the clean target. PTAL :)

thank you for taking the time to review!

@fxdgear
Copy link
Contributor Author

fxdgear commented Jul 9, 2018

@jarpy PTAL I added a new commit which updates the README to account for the 2 env vars needed to make this work on Windows: 6d1941f

@jarpy
Copy link
Contributor

jarpy commented Jul 10, 2018

Thanks, @fxdgear.

Still not behaving itself on my Windows machine, I'm afraid.

λ  (pwd).path
C:\Users\jarpy\src\stack-docker

λ  $Env:COMPOSE_CONVERT_WINDOWS_PATHS=1

λ  $Env:PWD="/c/Users/jarpy/src/stack-docker"

λ  docker-compose -f setup.yml up
Starting stack-docker_setup_1 ... done
Attaching to stack-docker_setup_1
setup_1  | cat: can't open './scripts/setup.sh': No such file or directory
stack-docker_setup_1 exited with code 0

scripts/setup.sh Outdated
@@ -4,6 +4,9 @@ chown 1000 -R "$confdir"
find "$confdir" -type f -name "*.keystore" -exec chmod go-wrx {} \;
find "$confdir" -type f -name "*.yml" -exec chmod go-wrx {} \;

PW=$(date +%s | sha256sum | base64 | head -c 16 ;)

Choose a reason for hiding this comment

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

We shouldn't do this to generate the password, it will be predictable. Better to grab some data from /dev/urandom or use openssl

@jordansissel
Copy link

Possible error conditions I've found:

On second attempts to -f setup.yml up, some files may already exist:

  1. When elasticsearch.keystore exists, it is not regenerated. Still, a new ELASTIC_PASSWORD is generated and used in Kibana and Logstash, but not set in elasticsearch.keystore. Workaround: Remove elasticsearch.keystore and -f setup up again.

  2. Kibana's SSL files, when they already exist, may not be repopulated. Workaround: Remove all new/modified files in config/ and git checkout . to restore normal files, then -f setup up again.

@fxdgear
Copy link
Contributor Author

fxdgear commented Jul 11, 2018

@jordansissel if you have make installed you can run a make clean which will solve this as well. BUT unfortuanly make isn't installed by default on windows :(

Thank you so much for all your help on windows testing!

README.md Outdated
* `PWD=/path/to/checkout/for/stack-docker`
* for example I use the path: `/c/Users/nick/elastic/stack-docker`
* You can set these two ways:
1. in powershell use: `$Env:COMPOSE_CONVERT_WINDOWS_PATHS=1`
Copy link

Choose a reason for hiding this comment

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

This will only set the variable for the current PowerShell session, which may be OK for this?

The equivalent of option 2. would be

[Environment]::SetEnvironmentVariable("COMPOSE_CONVERT_WINDOWS_PATHS", "1", "Machine")

As per number 2, you'd need to start a new session after this, for the change to be picked up (or refresh the environment from the registry).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@russcam thanks! I had no idea you could do that! ;)

Possible fixes: Use curl's `-u` flag for user:pass, or use hex instead
of base64 for `openssl rand`. I chose `curl -u`

The bug is that base64 includes `/`, so the `openssl rand -base64 16`
password could contain a `/` and make curl think that the username is
really the hostname:

```
curl 'https://elastic:nfAvKVigT7Bd7R60/o+1OQ==@elasticsearch:9200/'
curl: (6) Could not resolve host: elastic; Unknown error
```

The bug manifests as setup_logstash and setup_kibana getting stuck
waiting for Elasticsearch to be online, but never succeeds because the
curl invocation is wonky.
@jordansissel
Copy link

Tested latest commit, and it works for me (Tested on Windows 10 / powershell).

@fxdgear
Copy link
Contributor Author

fxdgear commented Jul 12, 2018

@Crazybus can you please review again. I hope I've addressed all your changes.
@jordansissel +1 thanks for the patch super helpful.
@russcam Can you please review the README again. i've taken your suggestion and added it.
@jarpy When you have time lets sit down and see where you are blocked.

Copy link

@Crazybus Crazybus left a comment

Choose a reason for hiding this comment

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

LGTM! All is working well now when I blindly follow the readme 👍

As we discussed filebeat currently doesn't have any incoming data. An idea would be to mount the docker socket into the container and show the docker logs inside of this demo. However this is out of scope for this PR.

@fxdgear fxdgear merged commit 898d08b into master Jul 13, 2018
@russcam
Copy link

russcam commented Jul 16, 2018

The PowerShell environment variable change looks good @fxdgear 👍

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

Successfully merging this pull request may close these issues.

None yet

9 participants