-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
top file targeting: key length limit causing issues in large environments #52323
Comments
@Paulo-Nunes Can you offer an explanation as to why you state: Pillar top should not use grain targeting for security reasons Given that this is considered a feature of Salt especially in targeting different platforms with globbing, for example: 'G@os_family:Redhat and G@os:Amazon and not G@osmajorrelease:2': 'G@os_family:Redhat and G@os:Amazon and G@osmajorrelease:2': 'G@os_family:Redhat and G@osmajorrelease:7 and not G@os:Amazon': 'G@os_family:Redhat and G@osmajorrelease:6 and not G@os:Amazon': 'G@os_family:Debian and G@osmajorrelease:9 and not G@osfullname:Raspbian': 'G@os_family:Debian and G@osmajorrelease:8 and not G@osfullname:Raspbian': 'G@osfullname:Raspbian and G@osmajorrelease:9 and G@os_family:Debian': 'G@osfullname:Raspbian and G@osmajorrelease:8 and G@os_family:Debian': |
Grain targeting in state top is fine as long as there is no sensitive data. As an example, lets say I have a grain
Within that pillar file there could be sensitive information or things we don't want other minions to be privy to. Even if data is gpg encrypted the minion should have the ability to decrypt the pillar if memory serves me. But even if not, sometimes just the structure of the pillar could be information an attacker could use. By using minion ID we prevent that method of attack. Or is the minion ID easily spoof-able as well? I am a fan of using grains in a compound with
This adds some redundancy and readability as well as helping to make sure all minions are grained appropriately, but not by itself. Since I raised this question I have thought of 2 ways that I might try to work around this, but neither is great. One would require upgrading to the newest version, but there is an open issue that was affecting the master/minions in 2018.3 that required a downgrade and I haven't seen anything to suggest it has been resolved in 2019.2 (#49863) Update |
@Paulo-Nunes The item you refer to in #49863 was entirely something differed, it was an issue in the version of pycryptodomex v3.4 which was corrected in v3.6, in that they were handling armored files incorrectly w.r.t to RSA being included. The other part of that issue was that RHEL 7.2 shipped with openssl v1.0.1 and not v1.0.2k as in CentOS 7.2, RHEL 7.5 how ships with v1.0.2, hence had to ship a version of openssl v1.0.2k for those used using RHEL 7.2. Mitigation would be to use M2Crypto instead of pycryptodomex since it has become an active project again in the last couple of years. If an attacker gets access to a minion, then in a way all bets are off, since as root on a minion who knows what they could introduce and do: ship all keys to be broken, etc. However Salt does encrypt communication between the master and the minion pillar information, and the master is unlikely to be affected by anything on the minion, however the minion if compromised could trick the master into allowing packages to be installed on to it which may not be correct, for example: Debian system claiming to be Redhat. So yes, there could be issues using Pillar top and grain targeting, and the 'id' would be harder to spoof. but currently that is how they are used. To navigate around the 1K limit on yaml, your could load the keys etc as JSON which would not have a limit, since essentially the yaml is parsed into JSON and the result loaded. Googling should bring up examples where users have done similar. If the suggestion of using JSON to circumvent YAML 1K limits is sufficient, please consider closing this issue. |
My aim was to find the Salt approved way of dealing with this limitation. If using JSON is the approved method then that should be sufficient. Could you explain/provide a simple example of this? I am having a hard time understanding how this would work. Are you saying to use the JSON renderer instead of the YAML default renderer on the entire top file? When you say "load the keys etc as JSON" do you mean to use For the sake of others, the 2 methods I was thinking of are: jinja loops and nodegroups. In 2019.2 nodegroups can be used as Jinja loops would be another way to do this, but it would make the top file a bit messy.
This would render to something like:
In this example I have all my minions defined in another file as YAML that I read into the top and render using jinja into the key:
The above however does not work with many minions |
@Paulo-Nunes You correct, for targeting pillar values we do not recommend using Grains because the are stored on the minion and can be easily be overridden. For targeting the number of minions you're looking to target, nodegroups are definitely a good option, but you could also look at adding some regular expressions in as well. https://docs.saltstack.com/en/latest/topics/targeting/globbing.html#regular-expressions |
@garethgreenaway The problem with regex (and the same reason I mention no globbing) is because I am not necessarily aware of what the server IDs will be ahead of time. Yes nodegroups are an option I gave some thought to, but it has some drawbacks. One is it forces me to upgrade salt to be able to use it. Another is that the nodegroup file is stored on the master instead of the git filesystem where the states live. Another still is the requirement of restarting the master on edit. Regex would work if we could guarantee consistent naming, but we can't. I find regex to be difficult for people to understand unless they are very familiar with it. The ideal solution would be: |
@Paulo-Nunes a top file is passed through rendering pipeline like any other file, just add a shebang and you can generate any other type of data, whether that is python dict, json, etc. |
@mattp- But can we have:
Would I have to write the entire top in JSON format? That is not ideal because it is much harder to read and maintain. Ideally I would like to keep the YAML formatting as much as possible because of consistency and readability/maintainability. I don't like the idea of changing the format of my files because the size of the environment reaches some threshold. |
yes, you'd need to rewrite it for json. that said what you are actually trying to do could be served by node groups defined in your master conf. that way you could stay in yaml and avoid this problem. |
Unfortunately it seems like using node groups is high on the list of viable options. It has its downsides as I noted earlier. The two worst negatives for me is the need to restart the salt master for new node groups to work, and the upgrade to new salt( tried it and ran into some breaking behavior that needs to be resolved). To automate things I am generating a list of minions grouped by roles, writing that to a file, and using jinja to load those into the top. In essence I am creating node groups, but they render out to yaml and that is what causes the issue (hitting the character limit). If there is no great way of doing this I might have to settle for node groups. A little disappointed salt cant handle many minions using the same standards/best practices it uses for few minions. Something that would be cool to have would be a way to tag a portion of the top to use a separate renderer:
they would both render out to python data structure and then be merged into one or have a way to add a
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue. |
Description of Issue/Question
It seems that YAML has a key limit of 1024 characters:(https://yaml.org/spec/1.1/#simple%20key/)
as noted in the salt doc: (https://docs.saltstack.com/en/latest/topics/troubleshooting/yaml_idiosyncrasies.html#keys-limited-to-1024-characters)
Pillar top should not use grain targeting for security reasons. I use list of hostnames, but when there are hundreds of minions this limit of 1024 characters is quickly met.
What is the "Salt" way of handling hundreds of minions in pillar when the key length would exceed 1024? Could this be done when globing is not an option and IP ranges are not sequential?
Setup
(Please provide relevant configs and/or SLS files (Be sure to remove sensitive info).)
This is an example of the pillar top line causing an issue:
Steps to Reproduce Issue
(Include debug logs if possible and relevant.)
Versions Report
(Provided by running
salt --versions-report
. Please also mention any differences in master/minion versions.)The text was updated successfully, but these errors were encountered: