-
Notifications
You must be signed in to change notification settings - Fork 613
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into v1.83.0-stage
- Loading branch information
Showing
5 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,45 @@ | ||
//go:build linux | ||
// +build linux | ||
|
||
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
// not use this file except in compliance with the License. A copy of the | ||
// License is located at | ||
// | ||
// http://aws.amazon.com/apache2.0/ | ||
// | ||
// or in the "license" file accompanying this file. This file 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. | ||
|
||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/aws/amazon-ecs-agent/ecs-agent/logger" | ||
) | ||
|
||
const FIPSModeFilePath = "/proc/sys/crypto/fips_enabled" | ||
|
||
// DetectFIPSMode checks if FIPS mode is enabled based on the provided file path. | ||
func DetectFIPSMode(filePath string) bool { | ||
data, err := os.ReadFile(filePath) | ||
if err != nil { | ||
logger.Debug(fmt.Sprintf("Error while detecting FIPS is enabled or not, err: %v", err)) | ||
return false | ||
} | ||
|
||
fipsValue := strings.TrimSpace(string(data)) | ||
if fipsValue == "1" { | ||
logger.Info("FIPS mode detected on the host") | ||
return true | ||
} | ||
|
||
logger.Debug(fmt.Sprintf("FIPS mode not enabled. FIPS mode explicitly set to %v", fipsValue)) | ||
return false | ||
} |
This file contains 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,52 @@ | ||
//go:build linux && unit | ||
// +build linux,unit | ||
|
||
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
// not use this file except in compliance with the License. A copy of the | ||
// License is located at | ||
// | ||
// http://aws.amazon.com/apache2.0/ | ||
// | ||
// or in the "license" file accompanying this file. This file 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. | ||
|
||
package utils | ||
|
||
import ( | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDetectFIPSMode(t *testing.T) { | ||
// Create a temporary file to mock the FIPS mode file | ||
tempFile, err := ioutil.TempFile("", "fips_enabled") | ||
assert.NoError(t, err) | ||
defer os.Remove(tempFile.Name()) | ||
// Test FIPS mode enabled | ||
_, err = tempFile.WriteString("1\n") | ||
assert.NoError(t, err) | ||
tempFile.Sync() | ||
// Initialize the logger | ||
log.SetFlags(log.LstdFlags | log.Lshortfile) | ||
result := DetectFIPSMode(tempFile.Name()) | ||
assert.True(t, result, "FIPS mode should be detected") | ||
// Test FIPS mode disabled | ||
tempFile.Truncate(0) | ||
tempFile.Seek(0, 0) | ||
_, err = tempFile.WriteString("0\n") | ||
assert.NoError(t, err) | ||
tempFile.Sync() | ||
result = DetectFIPSMode(tempFile.Name()) | ||
assert.False(t, result, "FIPS mode should not be detected") | ||
// Test when the FIPS file does not exist | ||
result = DetectFIPSMode("nonexistent_file") | ||
assert.False(t, result, "FIPS mode should not be detected when file is missing") | ||
} |
This file contains 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,28 @@ | ||
//go:build !windows && !linux | ||
// +build !windows,!linux | ||
|
||
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
// not use this file except in compliance with the License. A copy of the | ||
// License is located at | ||
// | ||
// http://aws.amazon.com/apache2.0/ | ||
// | ||
// or in the "license" file accompanying this file. This file 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. | ||
|
||
package utils | ||
|
||
import ( | ||
"github.com/aws/amazon-ecs-agent/ecs-agent/logger" | ||
) | ||
|
||
const FIPSModeFilePath = "" | ||
|
||
func DetectFIPSMode(filepath string) bool { | ||
logger.Debug("FIPS mode detection is not supported on this platform") | ||
return false | ||
} |
This file contains 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,28 @@ | ||
//go:build windows && !linux | ||
// +build windows,!linux | ||
|
||
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
// not use this file except in compliance with the License. A copy of the | ||
// License is located at | ||
// | ||
// http://aws.amazon.com/apache2.0/ | ||
// | ||
// or in the "license" file accompanying this file. This file 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. | ||
|
||
package utils | ||
|
||
import ( | ||
"github.com/aws/amazon-ecs-agent/ecs-agent/logger" | ||
) | ||
|
||
const FIPSModeFilePath = "" | ||
|
||
func DetectFIPSMode(filepath string) bool { | ||
logger.Debug("set isFIPSEnabled to false by default on Windows") | ||
return false | ||
} |