-
Notifications
You must be signed in to change notification settings - Fork 625
Add IMA feature to the kernel, add config for it #135
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
dmcilvaney
merged 5 commits into
microsoft:1.0-dev
from
dmcilvaney:damcilva/add_kernel_cmdline_ima
Sep 25, 2020
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
97477b0
Add IMA feature to the kernel, add config for it
dmcilvaney 418efc2
Address feedback
dmcilvaney e7e7fac
Add some debug prints to the grub config edits
dmcilvaney abe57ca
Update toolkit/tools/imagegen/installutils/installutils.go
dmcilvaney c35b990
Update toolkit/tools/imagegen/installutils/installutils.go
dmcilvaney 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| { | ||
| "Signatures": { | ||
| "config": "cb99faaac82f05b84539e4b99633b5a444de5b2db01ed37946afa0360d1f94f0", | ||
| "config_aarch64": "98bcf0f9c9fa02e11ad255ae352461b8ef7d53daf02c707a8a9b53f9bfb32db3", | ||
| "config": "ac1f71bde2b05e417e5d4fe4a72ffa5b0376ac53136e61e7e080e4f2a97ef31c", | ||
| "config_aarch64": "5405f228f0da37ad2460047c83930f89d76f7697fd3835848ef2092587d78104", | ||
| "linux-msft-5.4.51.tar.gz": "3bcd6b09e952fac4f708614658b508ce80c8e25c04780b6b44a481b1479a08e7" | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| // Parser for the image builder's configuration schemas. | ||
|
|
||
| package configuration | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| ) | ||
|
|
||
| // ImaPolicy sets the ima_policy kernel command line option | ||
| type ImaPolicy string | ||
|
|
||
| const ( | ||
| // ImaPolicyTcb selects the tcb IMA policy | ||
| ImaPolicyTcb ImaPolicy = "tcb" | ||
| // ImaPolicyAppraiseTcb selects the appraise_tcb IMA policy | ||
| ImaPolicyAppraiseTcb ImaPolicy = "appraise_tcb" | ||
| // ImaPolicySecureBoot selects the secure_boot IMA policy | ||
| ImaPolicySecureBoot ImaPolicy = "secure_boot" | ||
| // ImaPolicyNone selects no IMA policy | ||
| ImaPolicyNone ImaPolicy = "" | ||
| ) | ||
|
|
||
| func (i ImaPolicy) String() string { | ||
| return fmt.Sprint(string(i)) | ||
| } | ||
|
|
||
| // GetValidImaPolicies returns a list of all the supported | ||
| // disk partition types | ||
| func (i *ImaPolicy) GetValidImaPolicies() (types []ImaPolicy) { | ||
| return []ImaPolicy{ | ||
| ImaPolicyTcb, | ||
| ImaPolicyAppraiseTcb, | ||
| ImaPolicySecureBoot, | ||
| ImaPolicyNone, | ||
| } | ||
| } | ||
|
|
||
| // IsValid returns an error if the ImaPolicy is not valid | ||
| func (i *ImaPolicy) IsValid() (err error) { | ||
| for _, valid := range i.GetValidImaPolicies() { | ||
| if *i == valid { | ||
| return | ||
| } | ||
| } | ||
| return fmt.Errorf("invalid value for ImaPolicy (%s)", i) | ||
| } | ||
|
|
||
| // UnmarshalJSON Unmarshals an ImaPolicy entry | ||
| func (i *ImaPolicy) UnmarshalJSON(b []byte) (err error) { | ||
| // Use an intermediate type which will use the default JSON unmarshal implementation | ||
| type IntermediateTypeImaPolicy ImaPolicy | ||
| err = json.Unmarshal(b, (*IntermediateTypeImaPolicy)(i)) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to parse [ImaPolicy]: %w", err) | ||
| } | ||
|
|
||
| // Now validate the resulting unmarshaled object | ||
| err = i.IsValid() | ||
| if err != nil { | ||
| return fmt.Errorf("failed to parse [ImaPolicy]: %w", err) | ||
| } | ||
| return | ||
| } |
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,78 @@ | ||
| // Copyright Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package configuration | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| // TestMain found in configuration_test.go. | ||
|
|
||
| var ( | ||
| validImaPolicies = []ImaPolicy{ | ||
| ImaPolicy("tcb"), | ||
| ImaPolicy("appraise_tcb"), | ||
| ImaPolicy("secure_boot"), | ||
| ImaPolicy(""), | ||
| } | ||
| invalidImaPolicy = ImaPolicy("not_a_policy") | ||
| validImaJSON = `"tcb"` | ||
| invalidImaJSON = `1234` | ||
| ) | ||
|
|
||
| func TestShouldSucceedValidImaPoliciesMatch_ImaPolicy(t *testing.T) { | ||
| var ima ImaPolicy | ||
| assert.Equal(t, len(validImaPolicies), len(ima.GetValidImaPolicies())) | ||
|
|
||
| for _, imaPolicy := range validImaPolicies { | ||
| found := false | ||
| for _, validImaPolicy := range ima.GetValidImaPolicies() { | ||
| if imaPolicy == validImaPolicy { | ||
| found = true | ||
| } | ||
| } | ||
| assert.True(t, found) | ||
| } | ||
| } | ||
|
|
||
| func TestShouldSucceedParsingValidPolicies_ImaPolicy(t *testing.T) { | ||
| for _, validPolicy := range validImaPolicies { | ||
| var checkedPolicy ImaPolicy | ||
|
|
||
| assert.NoError(t, validPolicy.IsValid()) | ||
| err := remarshalJSON(validPolicy, &checkedPolicy) | ||
| assert.NoError(t, err) | ||
| assert.Equal(t, validPolicy, checkedPolicy) | ||
| } | ||
| } | ||
|
|
||
| func TestShouldFailParsingInvalidPolicy_ImaPolicy(t *testing.T) { | ||
| var checkedPolicy ImaPolicy | ||
|
|
||
| err := invalidImaPolicy.IsValid() | ||
| assert.Error(t, err) | ||
| assert.Equal(t, "invalid value for ImaPolicy (not_a_policy)", err.Error()) | ||
|
|
||
| err = remarshalJSON(invalidImaPolicy, &checkedPolicy) | ||
| assert.Error(t, err) | ||
| assert.Equal(t, "failed to parse [ImaPolicy]: invalid value for ImaPolicy (not_a_policy)", err.Error()) | ||
| } | ||
|
|
||
| func TestShouldSucceedParsingValidJSON_ImaPolicy(t *testing.T) { | ||
| var checkedPolicy ImaPolicy | ||
|
|
||
| err := marshalJSONString(validImaJSON, &checkedPolicy) | ||
| assert.NoError(t, err) | ||
| assert.Equal(t, validImaPolicies[0], checkedPolicy) | ||
| } | ||
|
|
||
| func TestShouldFailParsingInvalidJSON_ImaPolicy(t *testing.T) { | ||
| var checkedPolicy ImaPolicy | ||
|
|
||
| err := marshalJSONString(invalidImaJSON, &checkedPolicy) | ||
| assert.Error(t, err) | ||
| assert.Equal(t, "failed to parse [ImaPolicy]: json: cannot unmarshal number into Go value of type configuration.IntermediateTypeImaPolicy", err.Error()) | ||
| } |
Oops, something went wrong.
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.