Skip to content
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

[RS-1592] - Changes WAF from Coraza back to ModSecurity. #3078

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions git-hooks/files-to-skip
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
api/v1/zz_generated.deepcopy.go
api/v1beta1/zz_generated.deepcopy.go
pkg/apis/crd.projectcalico.org/v1/zz_generated.deepcopy.go
pkg/render/applicationlayer/modsecurityrules.go
18 changes: 11 additions & 7 deletions pkg/controller/applicationlayer/applicationlayer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package applicationlayer

import (
"context"
"encoding/base64"
"errors"
"fmt"

Expand All @@ -28,7 +29,6 @@ import (
"github.com/tigera/operator/pkg/controller/utils/imageset"
"github.com/tigera/operator/pkg/render"
"github.com/tigera/operator/pkg/render/applicationlayer"
"github.com/tigera/operator/pkg/render/applicationlayer/embed"
rmeta "github.com/tigera/operator/pkg/render/common/meta"

corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -419,19 +419,23 @@ func (r *ReconcileApplicationLayer) getModSecurityRuleSet(ctx context.Context) (
}

func getDefaultCoreRuleset(ctx context.Context) (*corev1.ConfigMap, error) {
data, err := embed.AsMap()
if err != nil {
return nil, err
}

ruleset := &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{Kind: "ConfigMap", APIVersion: "v1"},
ObjectMeta: metav1.ObjectMeta{
Name: applicationlayer.ModSecurityRulesetConfigMapName,
Namespace: common.OperatorNamespace(),
},
Data: data,
Data: make(map[string]string),
}

for filename, dataBase64 := range applicationlayer.ModsecurityCoreRuleSet {
if data, err := base64.StdEncoding.DecodeString(dataBase64); err == nil {
ruleset.Data[filename] = string(data)
} else {
return nil, err
}
}

return ruleset, nil
}

Expand Down
24 changes: 8 additions & 16 deletions pkg/render/applicationlayer/applicationlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:generate go run gen.go

package applicationlayer

import (
"bytes"
_ "embed"
"fmt"
"path/filepath"
"strconv"
"strings"
"text/template"
Expand Down Expand Up @@ -58,11 +59,9 @@ const (
DikastesSyncVolumeName = "dikastes-sync"
DikastesContainerName = "dikastes"
ModSecurityRulesetVolumeName = "modsecurity-ruleset"
ModSecurityRulesetVolumePath = "/etc/modsecurity-ruleset"
ModSecurityRulesetConfigMapName = "modsecurity-ruleset"
ModSecurityRulesetHashAnnotation = "hash.operator.tigera.io/modsecurity-ruleset"
CalicoLogsVolumeName = "var-log-calico"
CalicologsVolumePath = "/var/log/calico"
)

func ApplicationLayer(
Expand Down Expand Up @@ -296,26 +295,19 @@ func (c *component) containers() []corev1.Container {
}

if c.config.WAFEnabled {
commandArgs = append(
commandArgs,
"--waf-enabled",
"--waf-log-file", filepath.Join(CalicologsVolumePath, "waf", "waf.log"),
"--waf-ruleset-base-dir", ModSecurityRulesetVolumePath,
"--waf-directive", "Include modsecdefault.conf",
"--waf-directive", "Include crs-setup.conf",
"--waf-directive", "Include tigera.conf",
"--waf-directive", "Include rules/*.conf",
)

commandArgs = append(commandArgs, "--rules", "/etc/modsecurity-ruleset")

volMounts = append(
volMounts,
[]corev1.VolumeMount{
{
Name: CalicoLogsVolumeName,
MountPath: CalicologsVolumePath,
MountPath: "/var/log/calico",
},
{
Name: ModSecurityRulesetVolumeName,
MountPath: ModSecurityRulesetVolumePath,
MountPath: "/etc/modsecurity-ruleset",
ReadOnly: true,
},
}...,
Expand Down Expand Up @@ -420,7 +412,7 @@ func (c *component) volumes() []corev1.Volume {
Name: CalicoLogsVolumeName,
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: CalicologsVolumePath,
Path: "/var/log/calico",
Type: &hostPathDirectoryOrCreate,
},
},
Expand Down

This file was deleted.

Loading