-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kuma-cp): remove value of secret when logging Secret Resources (#…
…5384) * feat(kuma-cp): remove value of secret when logging Secret Resources Signed-off-by: Marcin Skalski <marcin.skalski@konghq.com> (cherry picked from commit cddddc9) Signed-off-by: Marcin Skalski <marcin.skalski@konghq.com>
- Loading branch information
Showing
5 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package v1alpha1 | ||
|
||
import util_proto "github.com/kumahq/kuma/pkg/util/proto" | ||
|
||
func (ds *DataSource) MaskInlineDatasource() *DataSource { | ||
if ds == nil { | ||
return nil | ||
} | ||
if ds.GetInline().String() != "" { | ||
return &DataSource{ | ||
Type: &DataSource_Inline{Inline: util_proto.Bytes([]byte("***"))}, | ||
} | ||
} | ||
if ds.GetInlineString() != "" { | ||
return &DataSource{ | ||
Type: &DataSource_InlineString{InlineString: "***"}, | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package v1alpha1 | ||
|
||
func (s *Secret) MarshalLog() interface{} { | ||
return "***" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package mesh | ||
|
||
import ( | ||
"google.golang.org/protobuf/proto" | ||
|
||
mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1" | ||
) | ||
|
||
func (es *ExternalServiceResource) IsReachableFromZone(zone string) bool { | ||
return es.Spec.Tags[mesh_proto.ZoneTag] == "" || es.Spec.Tags[mesh_proto.ZoneTag] == zone | ||
} | ||
|
||
func (esl *ExternalServiceResourceList) MarshalLog() interface{} { | ||
maskedList := make([]*ExternalServiceResource, 0, len(esl.Items)) | ||
for _, es := range esl.Items { | ||
maskedList = append(maskedList, es.MarshalLog().(*ExternalServiceResource)) | ||
} | ||
return ExternalServiceResourceList{ | ||
Items: maskedList, | ||
Pagination: esl.Pagination, | ||
} | ||
} | ||
|
||
func (es *ExternalServiceResource) MarshalLog() interface{} { | ||
spec := proto.Clone(es.Spec).(*mesh_proto.ExternalService) | ||
if spec == nil { | ||
return es | ||
} | ||
net := spec.GetNetworking() | ||
if net == nil { | ||
return es | ||
} | ||
tls := net.GetTls() | ||
if tls == nil { | ||
return es | ||
} | ||
tls.CaCert = tls.CaCert.MaskInlineDatasource() | ||
tls.ClientCert = tls.ClientCert.MaskInlineDatasource() | ||
tls.ClientKey = tls.ClientKey.MaskInlineDatasource() | ||
return ExternalServiceResource{ | ||
Meta: es.Meta, | ||
Spec: spec, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package system | ||
|
||
import ( | ||
"github.com/kumahq/kuma/pkg/core/resources/model" | ||
) | ||
|
||
type secretResource struct { | ||
Meta model.ResourceMeta | ||
Spec string | ||
} | ||
|
||
func (l *SecretResourceList) MarshalLog() interface{} { | ||
list := make([]interface{}, 0, len(l.Items)) | ||
for _, res := range l.Items { | ||
list = append(list, res.MarshalLog()) | ||
} | ||
return list | ||
} | ||
|
||
func (sr *SecretResource) MarshalLog() interface{} { | ||
return secretResource{ | ||
Meta: sr.Meta, | ||
Spec: "***", | ||
} | ||
} | ||
|
||
func (l *GlobalSecretResourceList) MarshalLog() interface{} { | ||
list := make([]interface{}, 0, len(l.Items)) | ||
for _, res := range l.Items { | ||
list = append(list, res.MarshalLog()) | ||
} | ||
return list | ||
} | ||
|
||
func (gs *GlobalSecretResource) MarshalLog() interface{} { | ||
return secretResource{ | ||
Meta: gs.Meta, | ||
Spec: "***", | ||
} | ||
} |