Skip to content

Commit

Permalink
explicitly state inbound, outbound rules in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
shinebayar-g committed Nov 16, 2022
1 parent 5c9499d commit 71c23e9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions ufwhandler/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func CreateUfwRule(ch <-chan *types.ContainerJSON, c *cache.Cache) {

for _, rule := range ufwRules {
cmd := exec.Command("sudo", "ufw", "route", "allow", "proto", rule.Proto, "from", rule.CIDR, "to", containerIP, "port", rule.Port, "comment", containerName+":"+containerID+rule.Comment)
log.Println("ufw-docker-automated: Adding rule:", cmd)
log.Println("ufw-docker-automated: Adding inbound rule:", cmd)

var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
Expand Down Expand Up @@ -154,7 +154,7 @@ func CreateUfwRule(ch <-chan *types.ContainerJSON, c *cache.Cache) {
} else {
cmd = exec.Command("sudo", "ufw", "route", "allow", "from", containerIP, "to", rule.CIDR, "port", rule.Port, "comment", containerName+":"+containerID+rule.Comment)
}
log.Println("ufw-docker-automated: Adding rule:", cmd)
log.Println("ufw-docker-automated: Adding outbound rule:", cmd)

var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
Expand All @@ -173,7 +173,7 @@ func CreateUfwRule(ch <-chan *types.ContainerJSON, c *cache.Cache) {

// Handle deny all out
cmd := exec.Command("sudo", "ufw", "route", "deny", "from", containerIP, "to", "any", "comment", containerName+":"+containerID)
log.Println("ufw-docker-automated: Adding rule:", cmd)
log.Println("ufw-docker-automated: Adding outbound rule:", cmd)

var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
Expand Down
8 changes: 4 additions & 4 deletions ufwhandler/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func DeleteUfwRule(containerID <-chan string, c *cache.Cache) {
// Handle inbound rules
for _, rule := range container.UfwInboundRules {
cmd := exec.Command("sudo", "ufw", "route", "delete", "allow", "proto", rule.Proto, "from", rule.CIDR, "to", container.IPAddress, "port", rule.Port, "comment", container.Name+":"+id+rule.Comment)
log.Println("ufw-docker-automated: Deleting rule:", cmd)
log.Println("ufw-docker-automated: Deleting inbound rule:", cmd)

var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
Expand All @@ -37,7 +37,7 @@ func DeleteUfwRule(containerID <-chan string, c *cache.Cache) {
} else {
cmd = exec.Command("sudo", "ufw", "route", "delete", "allow", "from", container.IPAddress, "to", rule.CIDR, "port", rule.Port, "comment", container.Name+":"+id+rule.Comment)
}
log.Println("ufw-docker-automated: Deleting rule:", cmd)
log.Println("ufw-docker-automated: Deleting outbound rule:", cmd)

var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
Expand All @@ -52,7 +52,7 @@ func DeleteUfwRule(containerID <-chan string, c *cache.Cache) {
}
// Handle deny all out
cmd := exec.Command("sudo", "ufw", "route", "delete", "deny", "from", container.IPAddress, "to", "any", "comment", container.Name+":"+id)
log.Println("ufw-docker-automated: Deleting rule:", cmd)
log.Println("ufw-docker-automated: Deleting outbound rule:", cmd)

var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
Expand All @@ -65,7 +65,7 @@ func DeleteUfwRule(containerID <-chan string, c *cache.Cache) {
log.Println("ufw:", stdout.String())
}
} else {
log.Println("ufw-docker-automated: Container information not found")
log.Println("ufw-docker-automated: Container information not found in cache.")
continue
}
}
Expand Down

0 comments on commit 71c23e9

Please sign in to comment.