-
Notifications
You must be signed in to change notification settings - Fork 1.7k
AMBARI-26556: Add a way to encrypted configurations.json file in the ambari-agent's cache #4087
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
Open
prabhjyotsingh
wants to merge
10
commits into
apache:trunk
Choose a base branch
from
prabhjyotsingh:AMBARI-26556
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+229
−18
Open
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ce6e8b9
AMBARI-26556: Add a way to encrypted configurations.json file in the …
prabhjyotsingh d7c33c7
add unit test
prabhjyotsingh 7204f32
fix unit test and add some comments
prabhjyotsingh 75ca12e
add comment for the new value
prabhjyotsingh 3cc00bb
fix cryptography installation script
prabhjyotsingh a8c4659
Merge branch 'apache:trunk' into AMBARI-26556
prabhjyotsingh 6873e63
use ambari_pyaes instead of downloading a new one
prabhjyotsingh 50b907f
revert install-helper.sh
prabhjyotsingh 9f9d9bf
fix typo
prabhjyotsingh 19f722a
AMBARI-26556: remove salt from config and make it random
prabhjyotsingh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
ambari-agent/src/test/python/ambari_agent/TestClusterCache.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| """ | ||
| Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you under the Apache License, Version 2.0 (the | ||
| "License"); you may not use this file except in compliance | ||
| with the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| """ | ||
|
|
||
| from ambari_agent import main | ||
|
|
||
| main.MEMORY_LEAK_DEBUG_FILEPATH = "/tmp/memory_leak_debug.out" | ||
| import os | ||
| import tempfile | ||
| import shutil | ||
| from unittest import TestCase | ||
|
|
||
| from ambari_agent.ClusterCache import ClusterCache | ||
| from mock.mock import patch, MagicMock | ||
| from ambari_commons import OSCheck | ||
| from only_for_platform import os_distro_value | ||
|
|
||
|
|
||
| class TestCertGeneration(TestCase): | ||
| """ | ||
| Test suite for verifying encryption behavior of ClusterCache. | ||
|
|
||
| It covers: | ||
| - encryption/decryption round-trip when secret/salt are provided | ||
| - behavior when encryption is effectively disabled (no secret/salt) | ||
| """ | ||
|
|
||
| # so that ClusterCache initialization is OS-agnostic in this test. | ||
| @patch.object(OSCheck, "os_distribution", new=MagicMock(return_value=os_distro_value)) | ||
| def setUp(self): | ||
| # Create a temporary directory that will be cleaned up after each test. | ||
| self.tmpdir = tempfile.mkdtemp() | ||
| cluster_cache_dir = self.tmpdir + "/cluster_cache_dir" | ||
|
|
||
| # Instance with encryption enabled (secret and salt provided). | ||
| self.cluster_cache_encrypted = DummyClusterCache( | ||
| cluster_cache_dir, | ||
| "super_secret", | ||
| "super_secret_salt" | ||
| ) | ||
|
|
||
| # Instance with encryption disabled (no secret or salt). | ||
| self.cluster_cache_unencrypted = DummyClusterCache(cluster_cache_dir) | ||
|
|
||
| @patch.object(os, "chmod") | ||
| def test_enc(self, chmod_mock): | ||
| """ | ||
| Verify that: | ||
| - encrypted instance changes the data and can restore it back | ||
| - unencrypted instance is a no-op for encrypt/decrypt | ||
| """ | ||
| string_json = '{"a": 1, "b": 2}' | ||
|
|
||
| # Encrypted cache should not store raw JSON. | ||
| encrypted = self.cluster_cache_encrypted._encrypt_data(string_json) | ||
| self.assertNotEqual(string_json, encrypted) | ||
| # Round-trip must produce original JSON. | ||
| decrypted = self.cluster_cache_encrypted._decrypt_data(encrypted) | ||
| self.assertEqual(string_json, decrypted) | ||
|
|
||
| # For unencrypted cache, encrypt/decrypt should behave as pass-through. | ||
| string_json = '{"a": 1, "b": 2}' | ||
| encrypted = self.cluster_cache_unencrypted._encrypt_data(string_json) | ||
| self.assertEqual(string_json, encrypted) | ||
| decrypted = self.cluster_cache_unencrypted._decrypt_data(encrypted) | ||
| self.assertEqual(string_json, decrypted) | ||
|
|
||
| @patch.object(os, "chmod") | ||
| def test_encryption_enable(self, chmod_mock): | ||
| """ | ||
| Verify that _is_encryption_enabled reflects whether secret/salt were provided. | ||
| """ | ||
| # When secret/salt are given, encryption flag should reflect enabled status. | ||
| self.assertFalse(self.cluster_cache_encrypted._is_encryption_enabled()) | ||
|
|
||
| # When no secret/salt, encryption should be reported as disabled. | ||
| self.assertTrue(self.cluster_cache_unencrypted._is_encryption_enabled()) | ||
|
|
||
| def tearDown(self): | ||
| shutil.rmtree(self.tmpdir) | ||
|
|
||
| class DummyClusterCache(ClusterCache): | ||
| """ | ||
| Minimal ClusterCache subclass used only for unit testing. | ||
|
|
||
| It overrides get_cache_name to avoid depending on real production cache names. | ||
| """ | ||
| def get_cache_name(self): | ||
| # Dummy implementation just for tests. | ||
| return "configuration" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.