Skip to content

Commit

Permalink
feat(prose/golang): accept purpose of use via config for now
Browse files Browse the repository at this point in the history
For some reason peer metadata is not included with each request, so we cannot
reliably extract purpose of use from there. Before we figure it out, we are
going to accept it as a configuration option.
  • Loading branch information
qlonik committed Mar 14, 2024
1 parent 90c94a4 commit df87ef3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions privacy-profile-composer/pkg/envoyfilter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type config struct {
opaConfig string
presidioUrl string
internalCidrs []net.IPNet
purpose string
}

type ConfigParser struct {
Expand Down Expand Up @@ -104,6 +105,14 @@ func (p *ConfigParser) Parse(any *anypb.Any, callbacks api.ConfigCallbackHandler
}
}

if purpose, ok := configStruct["purpose"]; !ok {
return nil, fmt.Errorf("missing purpose")
} else if str, ok := purpose.(string); !ok {
return nil, fmt.Errorf("purpose: expect string while got %T", purpose)
} else {
conf.purpose = str
}

return conf, nil
}

Expand All @@ -130,6 +139,7 @@ func (p *ConfigParser) Merge(parent interface{}, child interface{}) interface{}

newConfig.opaEnforce = childConfig.opaEnforce
newConfig.internalCidrs = childConfig.internalCidrs
newConfig.purpose = childConfig.purpose

return &newConfig
}
Expand Down
2 changes: 1 addition & 1 deletion privacy-profile-composer/pkg/envoyfilter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func (f *Filter) runOPA(ctx context.Context, isDecode bool, dataItems []string)
// as simple.rego expects PII type & purpose to be passed as headers
// (i.e. as if we had an OPA sidecar)
Input: map[string]interface{}{
"purpose_of_use": f.headerMetadata.Purpose,
"purpose_of_use": f.config.purpose,
"data_items": dataItems,
// todo double check that this is non-null only in outbound and decode mode
"external_domain": f.thirdPartyURL, // path or null
Expand Down

0 comments on commit df87ef3

Please sign in to comment.