-
Notifications
You must be signed in to change notification settings - Fork 740
*: audit operator actions to hostPath volume #1232
*: audit operator actions to hostPath volume #1232
Conversation
Any examples what the audit log looks like? |
pkg/cluster/audit.go
Outdated
return nil | ||
} | ||
|
||
mountPath := "/var/tmp/etcd-operator/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a OperatorRoot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will always be mounted. so we need a flag to enable audit logging now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually "audit logging" might be a bad name. probably debug logging is more suitable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xiang90 Actually the OperatorRoot
filepath is not mounted/created before the debug logger is setup.
The OperatorRoot
path is created after that by the backup manager during the cluster setup by the backup manager while creating the credentials and config files from the aws secret.
https://github.com/coreos/etcd-operator/blob/master/pkg/cluster/backupstorage/s3.go#L35-L39
Although I agree an explicit flag to enable debugging is better than silently detecting the presence of the mountPath.
My only concern now is that when you mount a hostPath to /var/tmp/etcd-operator/
for debugging, and if you set up S3 backup, the credentials and config files will be written to the hostPath as well now. Even though they are deleted later when the cluster is destroyed successfully, just wondering if this is alright.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is OK to put them under the same operator root dir. but we do not want our debug logging to be deleted by any accident.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah the debug logging won't be deleted. Just the aws credential and config files setup by the backup manager. Alright then, I guess we're good to share the OperatorRoot
for debugging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is fine.
These logs were generated from a non-self hosted cluster creating the audit logs during testing. It was easier to perform more actions on a non-self hosted cluster to generate the audit. I'm generating more detailed logs for a self-hosted cluster via bootkube at the moment. Will post them here once I'm done. |
pkg/cluster/audit.go
Outdated
) | ||
|
||
func NewAuditLogger(cl *spec.Cluster, lg *logrus.Entry) *logrus.Logger { | ||
if cl.Spec.SelfHosted == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make this behavior explicit outside:
if selfhosted != nil {
c.AuditLogger = NewAuditLogger()
}
pkg/cluster/audit.go
Outdated
return l | ||
} | ||
|
||
func (c *Cluster) auditPodCreation(pod *v1.Pod, podCreationErr error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should provide an AuditLogger object instead of coupling it as Cluster methods.
pkg/cluster/audit.go
Outdated
} | ||
lg.Infof("detected the mountPath(%v): starting to audit operator actions to the mountPath", mountPath) | ||
|
||
fileName := mountPath + cl.Metadata.Name + ".log" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use path.join
pkg/util/k8sutil/pod_util.go
Outdated
@@ -168,3 +169,11 @@ func getPodReadyCondition(status *v1.PodStatus) *v1.PodCondition { | |||
} | |||
return nil | |||
} | |||
|
|||
func GetReadablePodSpec(pod *v1.Pod) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PodSpecToPrettyJSON
c065c7f
to
794bc81
Compare
@xiang90 @hongchaodeng Made the changes requested. The debug logger is now a separate object that appends to a log file for the cluster.
The pod spec is not printed for pods added/deleted because that makes the output too verbose. Logs for a 4 master node self hosted cluster. The following actions were performed:
|
i think it is still worth to add even though it can be verbose. |
cmd/operator/main.go
Outdated
@@ -72,6 +73,7 @@ var ( | |||
|
|||
func init() { | |||
flag.BoolVar(&analyticsEnabled, "analytics", true, "Send analytical event (Cluster Created/Deleted etc.) to Google Analytics") | |||
flag.BoolVar(&debug.DebugEnabled, "debug", false, "Enable debug logging of operator actions to a hostPath volume mounted at /var/tmp/etcd-operator/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enable-debug-file (also you can make this arg to take a actual file path. default can be /var/tmp/etcd-operator/debug.log
)
operator probably should not know about hostpath thing. it just writes logs to somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, actually enable-selfhosted-debug-log is better.
pkg/debug/debug_logger.go
Outdated
|
||
logger := logrus.WithField("pkg", "debug") | ||
|
||
mountPath := path.Join(constants.OperatorRoot, "debug") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can remove this. operator does not have to know anything about the host path mount.
it just logs to what is configured by the deployment when selfhosted-debug-log is enabled.
pkg/debug/debug_logger.go
Outdated
mountPath := path.Join(constants.OperatorRoot, "debug") | ||
_, err := os.Stat(mountPath) | ||
if os.IsNotExist(err) { | ||
logger.Errorf("No volumed mounted at mountPath(%v): debug logging will not be performed: %v", mountPath, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call createDirAll instead here.
794bc81
to
23701d4
Compare
More verbose logs which print pod spec for every pod created. The operator will now write the debug logs to a default path |
lgtm after addressing the flag merge issue discussed offline. thanks! |
23701d4
to
da8966f
Compare
@hongchaodeng please take a final look. I've tested it manually on a self hosted cluster.
|
4b74b32
to
33d360c
Compare
cmd/operator/main.go
Outdated
@@ -72,6 +73,7 @@ var ( | |||
|
|||
func init() { | |||
flag.BoolVar(&analyticsEnabled, "analytics", true, "Send analytical event (Cluster Created/Deleted etc.) to Google Analytics") | |||
flag.StringVar(&debug.DebugFilePath, "debug-logfile-path", "", "path where the debug logfile will be written, recommended to be under: /var/tmp/etcd-operator/debug/ to avoid any issue with lack of write permissions") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mention that it is only for self hosted cluster?
bbb8a9b
to
10d9823
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
10d9823
to
0900c9f
Compare
pkg/cluster/cluster.go
Outdated
c.debugLogger.LogMessage(fmt.Sprintf("pod (%s) not found while trying to delete it", name)) | ||
} | ||
} | ||
if c.cluster.Spec.SelfHosted != nil && c.debugLogger != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you enable/disable the logger during the initialization? then we do not need to check this everywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or just make it a function?
Like isDebugLoggerEnabled() ?
0900c9f
to
6a81898
Compare
pkg/cluster/cluster.go
Outdated
} | ||
} | ||
|
||
func (c *Cluster) IsDebugLoggerEnabled() bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this public?
6a81898
to
060f2c0
Compare
Partially addresses #1205
The operator will now audit the following actions for a self-hosted cluster to a hostPath volume:
To enable the auditing a hostPath volume must be mounted to the mountPath
/var/tmp/
as shown below. The hostPath itself can be anything but should ideally be/var/tmp
so that the operator can write to the volume even when running as the usernobody
with limited write permissions.The debug log file path can be specified by passing the flag
debug-logfile-path
to the operator.The path specified by the flag and the mountPath should be the same.