c# - Restrict service to internal network BUT load balancer? -
in our servicestack (v3)-based api, have services internal use only, we've put [restrict(internalonly = true)]
attribute on of our internal request dtos.
the problem use load balancing, , restricted services publicly accessible because ip calling api load balancer's ip, , therefore internal ip.
is there way circumvent this, internal services restricted internal ips except load balancer's ip?
i haven't seen built in way (see [restrict]
tests) restrict based on specific ips. can trivially filter requests using custom attribute:
public class allowlocalexcludinglbattribute : requestfilterattribute { public override void execute(ihttprequest req, ihttpresponse res, object requestdto) { // if request not local or belongs load balancer throw exception if(!req.islocal || req.remoteip == "10.0.0.1") throw new httperror(system.net.httpstatuscode.forbidden, "403", "service can accessed internally"); } }
then add [allowlocalexcludinglb]
on services or action methods have otherwise used [restrict]
attribute or use in conjunction other restrictions. replace 10.0.0.1
load balancer ip.
Comments
Post a Comment