-
Notifications
You must be signed in to change notification settings - Fork 819
Support to enable fips for the command sonic_installer #2154
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
Changes from 1 commit
9104614
14d873b
1ec84d6
37170d1
61c222c
c84f598
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -147,6 +147,11 @@ def _get_image_cmdline(self, image): | |
| with open(os.path.join(image_path, KERNEL_CMDLINE_NAME)) as f: | ||
| return f.read() | ||
|
|
||
| def _set_image_cmdline(self, image, cmdline): | ||
| image_path = self.get_image_path(image) | ||
| with open(os.path.join(image_path, KERNEL_CMDLINE_NAME), 'w') as f: | ||
| return f.write(cmdline) | ||
|
|
||
| def supports_package_migration(self, image): | ||
| if is_secureboot(): | ||
| # NOTE: unsafe until migration can guarantee migration safety | ||
|
|
@@ -205,6 +210,22 @@ def verify_next_image(self): | |
| image_path = os.path.join(self.get_image_path(image), DEFAULT_SWI_IMAGE) | ||
| return self._verify_secureboot_image(image_path) | ||
|
|
||
| def set_fips(self, image, enable): | ||
| if enable: | ||
| click.echo('Enabling FIPS...') | ||
| fips = "1" | ||
| else: | ||
| click.echo('Disabling FIPS...') | ||
| fips = "0" | ||
| cmdline = self._get_image_cmdline(image) | ||
| cmdline = re.sub(' sonic_fips=[^\s]', '', cmdline) + " sonic_fips=" + fips | ||
|
||
| self._set_image_cmdline(image, cmdline) | ||
| click.echo('Done') | ||
|
|
||
| def get_fips(self, image): | ||
| cmdline = self._get_image_cmdline(image) | ||
| return 'sonic_fips=1' in cmdline | ||
|
|
||
| def _verify_secureboot_image(self, image_path): | ||
| if is_secureboot(): | ||
| cert = self.getCert(image_path) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -637,6 +637,35 @@ def set_next_boot(image): | |
| sys.exit(1) | ||
| bootloader.set_next_image(image) | ||
|
|
||
| # Set fips for image | ||
| @sonic_installer.command('set-fips') | ||
| @click.argument('image') | ||
| @click.option('--disable-fips', is_flag=True, | ||
|
||
| help="Disable fips") | ||
| def set_fips(image): | ||
| """ Set fips for the image """ | ||
| bootloader = get_bootloader() | ||
| if image not in bootloader.get_installed_images(): | ||
|
||
| echo_and_log('Error: Image does not exist', LOG_ERR) | ||
| sys.exit(1) | ||
| enable_fips = not disable_fips | ||
| bootloader.set_fips(image, enable=enable_fips) | ||
| click.echo('Set fips for the image successfully') | ||
|
|
||
| # Get fips for image | ||
| @sonic_installer.command('get-fips') | ||
| @click.argument('image') | ||
| def get_fips(image): | ||
| """ Get the fips enabled or disabled status for the image """ | ||
| bootloader = get_bootloader() | ||
| if image not in bootloader.get_installed_images(): | ||
| echo_and_log('Error: Image does not exist', LOG_ERR) | ||
| sys.exit(1) | ||
| enable = bootloader.get_fips(image) | ||
| if enable: | ||
| click.echo("Fips is enabled") | ||
|
||
| else: | ||
| click.echo("Fips is disabled") | ||
|
|
||
| # Uninstall image | ||
| @sonic_installer.command('remove') | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just use
"1" if enable else "0"#ClosedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks.