@@ -46,16 +46,22 @@ var _ mid.RequestInterceptor = (*PrivacyMapper)(nil)
4646// PrivacyMapper is a RequestInterceptor that maps any pseudo names in certain
4747// requests to their real values and vice versa for responses.
4848type PrivacyMapper struct {
49- newDB firewalldb.NewPrivacyMapDB
50- randIntn func (int ) (int , error )
49+ newDB firewalldb.NewPrivacyMapDB
50+ randIntn func (int ) (int , error )
51+ sessionIDIndexDB session.IDToGroupIndex
5152}
5253
5354// NewPrivacyMapper returns a new instance of PrivacyMapper. The randIntn
5455// function is used to draw randomness for request field obfuscation.
5556func NewPrivacyMapper (newDB firewalldb.NewPrivacyMapDB ,
56- randIntn func (int ) (int , error )) * PrivacyMapper {
57+ randIntn func (int ) (int , error ),
58+ sessionIDIndexDB session.IDToGroupIndex ) * PrivacyMapper {
5759
58- return & PrivacyMapper {newDB : newDB , randIntn : randIntn }
60+ return & PrivacyMapper {
61+ newDB : newDB ,
62+ randIntn : randIntn ,
63+ sessionIDIndexDB : sessionIDIndexDB ,
64+ }
5965}
6066
6167// Name returns the name of the interceptor.
@@ -91,6 +97,12 @@ func (p *PrivacyMapper) Intercept(ctx context.Context,
9197 return nil , fmt .Errorf ("could not extract ID from macaroon" )
9298 }
9399
100+ // Get group ID for session ID.
101+ groupID , err := p .sessionIDIndexDB .GetGroupID (sessionID )
102+ if err != nil {
103+ return nil , err
104+ }
105+
94106 log .Tracef ("PrivacyMapper: Intercepting %v" , ri )
95107
96108 switch r := req .InterceptType .(type ) {
@@ -108,7 +120,7 @@ func (p *PrivacyMapper) Intercept(ctx context.Context,
108120 }
109121
110122 replacement , err := p .checkAndReplaceIncomingRequest (
111- ctx , r .Request .MethodFullUri , msg , sessionID ,
123+ ctx , r .Request .MethodFullUri , msg , groupID ,
112124 )
113125 if err != nil {
114126 return mid .RPCErr (req , err )
@@ -142,7 +154,7 @@ func (p *PrivacyMapper) Intercept(ctx context.Context,
142154 }
143155
144156 replacement , err := p .replaceOutgoingResponse (
145- ctx , r .Response .MethodFullUri , msg , sessionID ,
157+ ctx , r .Response .MethodFullUri , msg , groupID ,
146158 )
147159 if err != nil {
148160 return mid .RPCErr (req , err )
@@ -167,10 +179,10 @@ func (p *PrivacyMapper) Intercept(ctx context.Context,
167179// checkAndReplaceIncomingRequest inspects an incoming request and optionally
168180// modifies some of the request parameters.
169181func (p * PrivacyMapper ) checkAndReplaceIncomingRequest (ctx context.Context ,
170- uri string , req proto.Message , sessionID session.ID ) (proto.Message ,
182+ uri string , req proto.Message , groupID session.ID ) (proto.Message ,
171183 error ) {
172184
173- db := p .newDB (sessionID )
185+ db := p .newDB (groupID )
174186
175187 // If we don't have a handler for the URI, we don't allow the request
176188 // to go through.
@@ -193,9 +205,9 @@ func (p *PrivacyMapper) checkAndReplaceIncomingRequest(ctx context.Context,
193205// replaceOutgoingResponse inspects the responses before sending them out to the
194206// client and replaces them if needed.
195207func (p * PrivacyMapper ) replaceOutgoingResponse (ctx context.Context , uri string ,
196- resp proto.Message , sessionID session.ID ) (proto.Message , error ) {
208+ resp proto.Message , groupID session.ID ) (proto.Message , error ) {
197209
198- db := p .newDB (sessionID )
210+ db := p .newDB (groupID )
199211
200212 // If we don't have a handler for the URI, we don't allow the response
201213 // to go to avoid accidental leaks.
0 commit comments