I’m needing access to the user’s ip so I can do geo lookup and store what country and province the content was added from.
Not seeing anything about this in docs, only about principals and jwt claims in action metadata. What about other request headers like X-Forwarded-For?
And yeah the only metadata keys appear to be: Authorization, _kalix-jwt-claim-iat, _kalix-jwt-claim-name, _kalix-jwt-claim-sub
The client IP header needs an opt in to be available (as it has a slight performance overhead for each request). For the JVM SDK that is done by adding x-forwarded-for to the forwardedHeaders for the component(s) where you need it.
The API for doing that is a bit cumbersome though, you will need to drop down to calling Kalix#register yourself instead of using the generated KalixFactory, something like this (in Scala, Java should look roughly but not exactly the same):
def main(args: Array[String]): Unit = {
val kalix = Kalix()
.register(
MyActionProvider(
MyAction(_),
ActionOptions.defaults.withForwardHeaders(Set("x-forwarded-for"))
)
)
kalix.start()
}
I have manually verified deploying a service with x-forwarded-for enabled via the action options and see it forwarded as expected for both gRPC and transcoded HTTP calls.
I see in your snippet that you register the same controller action provider twice (PostControllerServiceActionProvider), the setting is probably lost and replaced by the second registration of the same provider, remove that and I’d expect it starts working.
Note that the X-Forwarded-For header is not automatically present when you run locally, in integration tests or do tunneled/proxied requests to the deployed service through kalix service proxy. To try it out via those paths you’d need to pass the header yourself with the gRPC/HTTP client you use.
Oy, indeed that’s what it was, I removed the second, redundant register of that component and now I get the header. I guess that’s a downside of registering that way, no strict checking that all components are there and only once. Sorry I missed that and thanks for you keen eye Johan! -m
I think there is no actual use case for register-replace a component like that, and that it would only happen by mistake, so we should probably turn it into an exception instead.