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

(PE-27794) add a puma status app #1452

Closed
wants to merge 2 commits into from
Closed

(PE-27794) add a puma status app #1452

wants to merge 2 commits into from

Conversation

tkishel
Copy link
Contributor

@tkishel tkishel commented Nov 29, 2019

Adds a status app, which can be removed when puma improves security in its status app.

@tkishel tkishel requested review from a team as code owners November 29, 2019 18:10
@tkishel
Copy link
Contributor Author

tkishel commented Nov 29, 2019

No longer requires vanagon changes.

@puppetcla
Copy link

CLA signed by all contributors.

@@ -21,6 +21,8 @@ def int_keys
def defaults
super.merge(
'port' => 62658,
'status-port' => 62659,
'status-token' => "bolt",
Copy link
Member

Choose a reason for hiding this comment

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

Is the token sensitive? Would we lay down one with pe? Can we use the ssl-{cert,key,ca-cert} for auth?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Puma 4.3.0 implements that in the built-in Status app. We could too, if we model:

puma/puma#2046
puma/puma#2052

But I kept the logic of this app identical to the app in the version of puma we currently ship.

Copy link
Member

Choose a reason for hiding this comment

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

I think we need to update our puma stack anyway. If we got on 4.3.0 we would still need the puma-stats gem?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, because the Status app ...

https://github.com/puma/puma/blob/master/lib/puma/app/status.rb

... includes both Control and Status, which, in principle, I think is inappropriate: the security requirements for querying status (metrics) are significantly different that the same for controlling (restarting / shutting down) the service.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that the metrics from Puppet Server do not require a client certificate/whitelist:

[root@pe-201921-replica-ha ~]# curl -k https://pe-201921-master.puppetdebug.vlan:8140/status/v1/services?level=debug 
{"puppet-profiler":{"service_version":"6.7.1","service_status_version":1,"detail_level":"debug","state" 
...
[root@pe-201921-master ~]# grep -rl pe-201921-replica-ha /etc/puppetlabs | wc -l
0

But I may be able to implement ssl:// in the plugin ...

Copy link
Member

Choose a reason for hiding this comment

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

OK. I ticketed updating puma https://tickets.puppetlabs.com/browse/PE-27840

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As a POC, I added the MiniSSL::ContextBuilder class from the current version of Puma to the plugin (I could simply remove it if we upgrade to Puma 4.3+) and can serve status via:

if config['status-host'] && config['status-port'] && config['status-token']
  plugin 'stats'
  bind_addr = +"ssl://#{config['status-host']}:#{config['status-port']}?"
  bind_addr << "cert=#{config['ssl-cert']}"
  bind_addr << "&key=#{config['ssl-key']}"
  bind_addr << "&ca=#{config['ssl-ca-cert']}"
  bind_addr << "&verify_mode=none"
  bind_addr << "&ssl_cipher_filter=#{config['ssl-cipher-suites'].join(':')}"
  stats_url bind_addr
  stats_token config['status-token']
end

And access that via:

[root@pe-201921-master ~]# curl https://pe-201921-master.puppetdebug.vlan:44634/puma-stats?token=ace
curl: (60) Peer's certificate issuer has been marked as not trusted by the user.

[root@pe-201921-master ~]# curl --insecure https://pe-201921-master.puppetdebug.vlan:44634/puma-stats?token=ace
{ "backlog": 0, "running": 0, "pool_capacity": 10, "max_threads": 10 }

[root@pe-201921-master ~]# curl --cacert /etc/puppetlabs/puppet/ssl/certs/ca.pem https://pe-201921-master.puppetdebug.vlan:44634/puma-stats?token=ace
{ "backlog": 0, "running": 0, "pool_capacity": 10, "max_threads": 10 }  

[root@pe-201921-master ~]# curl --cacert /etc/puppetlabs/puppet/ssl/certs/ca.pem https://pe-201921-master.puppetdebug.vlan:44634/puma-stats?token=zzz
Invalid stats auth token

Is there a direction to move forward that you prefer/recommend?

Copy link
Member

Choose a reason for hiding this comment

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

I will defer to @branan or @mcdonaldseanp on that. I don't fully understand the impact of having to manage a token for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay. Note that not specifying a token in config/transport_service_config.rb or conf.d/bolt-server.conf will disable the token requirement :)

@tkishel
Copy link
Contributor Author

tkishel commented Dec 3, 2019

Resulting in:

ACE Server: Running on Primary Master, https://pe-201921-master.puppetdebug.vlan:44634/puma-stats
Activity Service: Running on Primary Master, https://pe-201921-master.puppetdebug.vlan:4433/activity-api
Bolt Server: Running on Primary Master, https://pe-201921-master.puppetdebug.vlan:62659/puma-stats
Classifier: Running on Primary Master, https://pe-201921-master.puppetdebug.vlan:4433/classifier-api
Orchestrator: Running on Primary Master, https://pe-201921-master.puppetdebug.vlan:8143/orchestrator
PCP Broker: Running on Primary Master, wss://pe-201921-master.puppetdebug.vlan:8142/pcp
PCP Broker v2: Running on Primary Master, wss://pe-201921-master.puppetdebug.vlan:8142/pcp2
Puppet Server: Running on Primary Master, https://pe-201921-master.puppetdebug.vlan:8140/
PuppetDB: Running on Primary Master, https://pe-201921-master.puppetdebug.vlan:8081/pdb
RBAC: Running on Primary Master, https://pe-201921-master.puppetdebug.vlan:4433/rbac-api
2019-12-03 00:42:14 +0000
11 of 11 services are fully operational.

The connection is encrypted, but the client does not need to provide a certificate, same as with our other services. The token remains, to be parallel with the default Control/Status app.

@branan
Copy link
Contributor

branan commented Dec 3, 2019

If we're gonna maintain this puma stats thing, I'd prefer to pull it into our namespace and ensure it's a known gem to RE, etc.

But really, I think I'd prefer we get our version of Puma up-to-date, then try to upstream the ability to enable status without control. That way we're not maintaining anything 😎

@tkishel
Copy link
Contributor Author

tkishel commented Dec 3, 2019

I hear you ...

I've submitted a feature and pr to the puma repository to implement separate tokens for control and status actions in the (sigh) Control Server implemented as the Status app. If it is accepted, I can easily modify the associated PRs in our repositories to match.

puma/puma#2081
puma/puma#2082

That said, the puma-stats plugin/gem is a trivial fork of another (metrics) plugin that I would happily move into our namespace, and if we updated our Puma to 4.3.x or newer, would be almost identical to the implementation of the Status app (minus the control actions). An argument for implementing our own status code would be if we wanted to extend it beyond what puma offers.

@tkishel
Copy link
Contributor Author

tkishel commented Dec 13, 2019

Updated POC. Smaller footprint. Requires Puma 4.3.x

Include the puma-stats app/plugin locally rather than as a gem.
With this commit, a puma status app (the default or ours) is loaded.
Requires Puma 4.3.x
@tkishel tkishel changed the title (PE-27794) add the puma-stats app (PE-27794) add a puma status app Dec 14, 2019
@tkishel
Copy link
Contributor Author

tkishel commented Dec 18, 2019

Closing in favor of the simpler #1503

@tkishel tkishel closed this Dec 18, 2019
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.

None yet

4 participants