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

Fix SSH in prod #1476

Merged
merged 1 commit into from
May 4, 2021
Merged
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
49 changes: 23 additions & 26 deletions pkg/operator/controllers/routefix/routefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ const (
configmapName = "add-iptables"
configmapScriptName = "add_iptables.sh"
configmapScriptDir = "/tmp"
containerNameDrop = "drop-icmp"
containerNameDetect = "detect"
shellScriptLog = `while true;

shellScriptLog = `while true;
do
NOW=$(date "+%Y-%m-%d %H:%M:%S")
DROPPED_PACKETS=$(ovs-ofctl -O OpenFlow13 dump-flows br0 | sed -ne '/table=10,.* actions=drop/ { s/.* n_packets=//; s/,.*//; p }')
Expand All @@ -43,8 +42,8 @@ do
fi
sleep 60
done`
shellScriptDrop = `set -xe

shellScriptDrop = `set -xe
echo "I$(date "+%m%d %H:%M:%S.%N") - drop-icmp - start drop-icmp ${K8S_NODE}"
iptables -X CHECK_ICMP_SOURCE || true
iptables -N CHECK_ICMP_SOURCE || true
Expand All @@ -55,18 +54,18 @@ iptables -N ICMP_ACTION || true
iptables -F ICMP_ACTION
iptables -A ICMP_ACTION -j LOG
iptables -A ICMP_ACTION -j DROP
oc observe nodes -a '{ .status.addresses[1].address }' -- ` + configmapScriptDir + `/` + configmapScriptName
/host/usr/bin/oc observe nodes -a '{ .status.addresses[1].address }' -- ` + configmapScriptDir + `/` + configmapScriptName
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is change 1


shellScriptAddIptables = `#!/bin/sh
echo "Adding ICMP drop rule for '$2' "
echo "Adding ICMP drop rule for '$2' "
#iptables -C CHECK_ICMP_SOURCE -p icmp -s $2 -j ICMP_ACTION || iptables -A CHECK_ICMP_SOURCE -p icmp -s $2 -j ICMP_ACTION
if iptables -C CHECK_ICMP_SOURCE -p icmp -s $2 -j ICMP_ACTION
if iptables -C CHECK_ICMP_SOURCE -p icmp -s $2 -j ICMP_ACTION
then
echo "iptables already set for $2"
else
iptables -A CHECK_ICMP_SOURCE -p icmp -s $2 -j ICMP_ACTION
fi
#iptables -nvL
`
#iptables -nvL`
)

func (r *RouteFixReconciler) securityContextConstraints(ctx context.Context, name, serviceAccountName string) (*securityv1.SecurityContextConstraints, error) {
Expand All @@ -87,16 +86,15 @@ func (r *RouteFixReconciler) resources(ctx context.Context, cluster *arov1alpha1
if err != nil {
return nil, err
}
hostPathUnset := corev1.HostPathUnset
resourceCPU, err1 := resource.ParseQuantity("10m")
if err1 != nil {
return nil, err1
resourceCPU, err := resource.ParseQuantity("10m")
if err != nil {
return nil, err
}
resourceMemory, err2 := resource.ParseQuantity("300Mi")
if err2 != nil {
return nil, err2
resourceMemory, err := resource.ParseQuantity("300Mi")
if err != nil {
return nil, err
}
defaultMode555 := int32(0555)

return []runtime.Object{
&corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -154,7 +152,7 @@ func (r *RouteFixReconciler) resources(ctx context.Context, cluster *arov1alpha1
ServiceAccountName: serviceAccountName,
Containers: []corev1.Container{
{
Name: containerNameDrop,
Name: "drop-icmp",
Image: image,
Args: []string{
"sh",
Expand All @@ -178,8 +176,8 @@ func (r *RouteFixReconciler) resources(ctx context.Context, cluster *arov1alpha1
},
VolumeMounts: []corev1.VolumeMount{
{
Name: "host-slash",
MountPath: "/",
Name: "host",
MountPath: "/host",
Comment on lines -181 to +180
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is change 2

ReadOnly: false,
},
{
Expand Down Expand Up @@ -207,7 +205,7 @@ func (r *RouteFixReconciler) resources(ctx context.Context, cluster *arov1alpha1
},
},
{
Name: containerNameDetect,
Name: "detect",
Image: image,
Args: []string{
"sh",
Expand All @@ -220,8 +218,8 @@ func (r *RouteFixReconciler) resources(ctx context.Context, cluster *arov1alpha1
},
VolumeMounts: []corev1.VolumeMount{
{
Name: "host-slash",
MountPath: "/",
Name: "host",
MountPath: "/host",
ReadOnly: true,
},
},
Expand All @@ -240,11 +238,10 @@ func (r *RouteFixReconciler) resources(ctx context.Context, cluster *arov1alpha1
},
Volumes: []corev1.Volume{
{
Name: "host-slash",
Name: "host",
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: "/",
Type: &hostPathUnset,
},
},
},
Expand All @@ -255,7 +252,7 @@ func (r *RouteFixReconciler) resources(ctx context.Context, cluster *arov1alpha1
LocalObjectReference: corev1.LocalObjectReference{
Name: configmapName,
},
DefaultMode: &defaultMode555,
DefaultMode: to.Int32Ptr(0555),
},
},
},
Expand Down