|
| 1 | +// Copyright The OpenTelemetry Authors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package fips |
| 16 | + |
| 17 | +import ( |
| 18 | + "strings" |
| 19 | +) |
| 20 | + |
| 21 | +type FIPSCheck interface { |
| 22 | + // DisabledComponents checks if a submitted components are denied or not. |
| 23 | + DisabledComponents(receivers map[string]interface{}, exporters map[string]interface{}, processors map[string]interface{}, extensions map[string]interface{}) []string |
| 24 | +} |
| 25 | + |
| 26 | +// FipsCheck holds configuration for FIPS deny list. |
| 27 | +type fipsCheck struct { |
| 28 | + receivers map[string]bool |
| 29 | + exporters map[string]bool |
| 30 | + processors map[string]bool |
| 31 | + extensions map[string]bool |
| 32 | +} |
| 33 | + |
| 34 | +// NewFipsCheck creates new FipsCheck. |
| 35 | +func NewFipsCheck(receivers, exporters, processors, extensions []string) FIPSCheck { |
| 36 | + return &fipsCheck{ |
| 37 | + receivers: listToMap(receivers), |
| 38 | + exporters: listToMap(exporters), |
| 39 | + processors: listToMap(processors), |
| 40 | + extensions: listToMap(extensions), |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +func listToMap(list []string) map[string]bool { |
| 45 | + m := map[string]bool{} |
| 46 | + for _, v := range list { |
| 47 | + m[v] = true |
| 48 | + } |
| 49 | + return m |
| 50 | +} |
| 51 | + |
| 52 | +func (fips fipsCheck) DisabledComponents(receivers map[string]interface{}, exporters map[string]interface{}, processors map[string]interface{}, extensions map[string]interface{}) []string { |
| 53 | + var disabled []string |
| 54 | + if comp := isDisabled(fips.receivers, receivers); comp != "" { |
| 55 | + disabled = append(disabled, comp) |
| 56 | + } |
| 57 | + if comp := isDisabled(fips.exporters, exporters); comp != "" { |
| 58 | + disabled = append(disabled, comp) |
| 59 | + } |
| 60 | + if comp := isDisabled(fips.processors, processors); comp != "" { |
| 61 | + disabled = append(disabled, comp) |
| 62 | + } |
| 63 | + if comp := isDisabled(fips.extensions, extensions); comp != "" { |
| 64 | + disabled = append(disabled, comp) |
| 65 | + } |
| 66 | + return disabled |
| 67 | +} |
| 68 | + |
| 69 | +func isDisabled(denyList map[string]bool, cfg map[string]interface{}) string { |
| 70 | + for id := range cfg { |
| 71 | + component := strings.Split(id, "/")[0] |
| 72 | + if denyList[component] { |
| 73 | + return component |
| 74 | + } |
| 75 | + } |
| 76 | + return "" |
| 77 | +} |
0 commit comments