forked from open-telemetry/opentelemetry-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add FIPS disabled components flag Signed-off-by: Pavol Loffay <p.loffay@gmail.com> * Fix Signed-off-by: Pavol Loffay <p.loffay@gmail.com> * Fix Signed-off-by: Pavol Loffay <p.loffay@gmail.com> * Fix Signed-off-by: Pavol Loffay <p.loffay@gmail.com> * Fix Signed-off-by: Pavol Loffay <p.loffay@gmail.com> * Fix Signed-off-by: Pavol Loffay <p.loffay@gmail.com> --------- Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
- Loading branch information
1 parent
218ff4a
commit 05c901f
Showing
13 changed files
with
243 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: enhancement | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action) | ||
component: collector | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Add flag to disable components when operator runs on FIPS enabled cluster. | ||
|
||
# One or more tracking issues related to the change | ||
issues: [3315] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: | | ||
Flag `--fips-disabled-components=receiver.otlp,exporter.otlp,processor.batch,extension.oidc` can be used to disable | ||
components when operator runs on FIPS enabled cluster. The operator uses `/proc/sys/crypto/fips_enabled` to check | ||
if FIPS is enabled. |
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
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
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,39 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed 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. | ||
|
||
package fips | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
"strings" | ||
) | ||
|
||
const fipsFile = "/proc/sys/crypto/fips_enabled" | ||
|
||
// IsFipsEnabled checks whether FIPS is enabled on the platform. | ||
func IsFipsEnabled() bool { | ||
// check if file exists | ||
if _, err := os.Stat(fipsFile); errors.Is(err, os.ErrNotExist) { | ||
return false | ||
} | ||
content, err := os.ReadFile(fipsFile) | ||
if err != nil { | ||
// file cannot be read, enable FIPS to avoid any violations | ||
return true | ||
} | ||
contentStr := string(content) | ||
contentStr = strings.TrimSpace(contentStr) | ||
return contentStr == "1" | ||
} |
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
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,77 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed 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. | ||
|
||
package fips | ||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
type FIPSCheck interface { | ||
// DisabledComponents checks if a submitted components are denied or not. | ||
DisabledComponents(receivers map[string]interface{}, exporters map[string]interface{}, processors map[string]interface{}, extensions map[string]interface{}) []string | ||
} | ||
|
||
// FipsCheck holds configuration for FIPS deny list. | ||
type fipsCheck struct { | ||
receivers map[string]bool | ||
exporters map[string]bool | ||
processors map[string]bool | ||
extensions map[string]bool | ||
} | ||
|
||
// NewFipsCheck creates new FipsCheck. | ||
func NewFipsCheck(receivers, exporters, processors, extensions []string) FIPSCheck { | ||
return &fipsCheck{ | ||
receivers: listToMap(receivers), | ||
exporters: listToMap(exporters), | ||
processors: listToMap(processors), | ||
extensions: listToMap(extensions), | ||
} | ||
} | ||
|
||
func listToMap(list []string) map[string]bool { | ||
m := map[string]bool{} | ||
for _, v := range list { | ||
m[v] = true | ||
} | ||
return m | ||
} | ||
|
||
func (fips fipsCheck) DisabledComponents(receivers map[string]interface{}, exporters map[string]interface{}, processors map[string]interface{}, extensions map[string]interface{}) []string { | ||
var disabled []string | ||
if comp := isDisabled(fips.receivers, receivers); comp != "" { | ||
disabled = append(disabled, comp) | ||
} | ||
if comp := isDisabled(fips.exporters, exporters); comp != "" { | ||
disabled = append(disabled, comp) | ||
} | ||
if comp := isDisabled(fips.processors, processors); comp != "" { | ||
disabled = append(disabled, comp) | ||
} | ||
if comp := isDisabled(fips.extensions, extensions); comp != "" { | ||
disabled = append(disabled, comp) | ||
} | ||
return disabled | ||
} | ||
|
||
func isDisabled(denyList map[string]bool, cfg map[string]interface{}) string { | ||
for id := range cfg { | ||
component := strings.Split(id, "/")[0] | ||
if denyList[component] { | ||
return component | ||
} | ||
} | ||
return "" | ||
} |
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,32 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed 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. | ||
|
||
package fips | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFipsCheck(t *testing.T) { | ||
fipsCheck := NewFipsCheck([]string{"rec1", "rec2"}, []string{"exp1"}, []string{"processor"}, []string{"ext1"}) | ||
blocked := fipsCheck.DisabledComponents( | ||
map[string]interface{}{"otlp": true, "rec1/my": true}, | ||
map[string]interface{}{"exp1": true}, | ||
map[string]interface{}{"processor": true}, | ||
map[string]interface{}{"ext1": true}) | ||
|
||
assert.Equal(t, []string{"rec1", "exp1", "processor", "ext1"}, blocked) | ||
} |
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
Oops, something went wrong.