-
Notifications
You must be signed in to change notification settings - Fork 1.1k
cc_keys_to_console: add option to disable key emission #811
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a1da330
add no_keys_to_console option to suppress cc_keys_to_console
mwhudson 40a5655
cc_keys_to_console: use ssh namespace for configuration
OddBloke 8fcc0ec
integration_tests: port cc_keys_to_console cloud tests
OddBloke ad01914
integration_tests: add tests for disabling cc_keys_to_console
OddBloke 7b9d8d1
Drop cloud_tests
OddBloke f5c7410
Merge branch 'master' into lp-1915460
OddBloke 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| """Tests for cc_keys_to_console.""" | ||
| from unittest import mock | ||
|
|
||
| import pytest | ||
|
|
||
| from cloudinit.config import cc_keys_to_console | ||
|
|
||
|
|
||
| class TestHandle: | ||
| """Tests for cloudinit.config.cc_keys_to_console.handle. | ||
|
|
||
| TODO: These tests only cover the emit_keys_to_console config option, they | ||
| should be expanded to cover the full functionality. | ||
| """ | ||
|
|
||
| @mock.patch("cloudinit.config.cc_keys_to_console.util.multi_log") | ||
| @mock.patch("cloudinit.config.cc_keys_to_console.os.path.exists") | ||
| @mock.patch("cloudinit.config.cc_keys_to_console.subp.subp") | ||
| @pytest.mark.parametrize("cfg,subp_called", [ | ||
| ({}, True), # Default to emitting keys | ||
| ({"ssh": {}}, True), # Default even if we have the parent key | ||
| ({"ssh": {"emit_keys_to_console": True}}, True), # Explicitly enabled | ||
| ({"ssh": {"emit_keys_to_console": False}}, False), # Disabled | ||
| ]) | ||
| def test_emit_keys_to_console_config( | ||
| self, m_subp, m_path_exists, _m_multi_log, cfg, subp_called | ||
| ): | ||
| # Ensure we always find the helper | ||
| m_path_exists.return_value = True | ||
| m_subp.return_value = ("", "") | ||
|
|
||
| cc_keys_to_console.handle("name", cfg, mock.Mock(), mock.Mock(), ()) | ||
|
|
||
| assert subp_called == (m_subp.call_count == 1) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| """Integration tests for the cc_keys_to_console module. | ||
|
|
||
| (This is ported from | ||
| ``tests/cloud_tests/testcases/modules/keys_to_console.yaml``.)""" | ||
| import pytest | ||
|
|
||
| BLACKLIST_USER_DATA = """\ | ||
| #cloud-config | ||
| ssh_fp_console_blacklist: [ssh-dss, ssh-dsa, ecdsa-sha2-nistp256] | ||
| ssh_key_console_blacklist: [ssh-dss, ssh-dsa, ecdsa-sha2-nistp256] | ||
| """ | ||
|
|
||
| DISABLED_USER_DATA = """\ | ||
| #cloud-config | ||
| ssh: | ||
| emit_keys_to_console: false | ||
| """ | ||
|
|
||
|
|
||
| @pytest.mark.user_data(BLACKLIST_USER_DATA) | ||
| class TestKeysToConsoleBlacklist: | ||
| """Test that the blacklist options work as expected.""" | ||
| @pytest.mark.parametrize("key_type", ["DSA", "ECDSA"]) | ||
| def test_excluded_keys(self, class_client, key_type): | ||
| syslog = class_client.read_from_file("/var/log/syslog") | ||
| assert "({})".format(key_type) not in syslog | ||
|
|
||
| @pytest.mark.parametrize("key_type", ["ED25519", "RSA"]) | ||
| def test_included_keys(self, class_client, key_type): | ||
| syslog = class_client.read_from_file("/var/log/syslog") | ||
| assert "({})".format(key_type) in syslog | ||
|
|
||
|
|
||
| @pytest.mark.user_data(DISABLED_USER_DATA) | ||
| class TestKeysToConsoleDisabled: | ||
| """Test that output can be fully disabled.""" | ||
| @pytest.mark.parametrize("key_type", ["DSA", "ECDSA", "ED25519", "RSA"]) | ||
| def test_keys_excluded(self, class_client, key_type): | ||
| syslog = class_client.read_from_file("/var/log/syslog") | ||
| assert "({})".format(key_type) not in syslog | ||
|
|
||
| def test_header_excluded(self, class_client): | ||
| syslog = class_client.read_from_file("/var/log/syslog") | ||
| assert "BEGIN SSH HOST KEY FINGERPRINTS" not in syslog | ||
|
|
||
| def test_footer_excluded(self, class_client): | ||
| syslog = class_client.read_from_file("/var/log/syslog") | ||
| assert "END SSH HOST KEY FINGERPRINTS" not in syslog |
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.