Closed mattdean-digicatapult closed 5 years ago
Thanks @mattdean-digicatapult for reporting. Happy to see Basic Station support on Kerlink Wirnet Stations also. Please upvote #1140 as adding documentation for this gateway is on our radar. I'll need to check with Kerlink what their status is with Basic Station, or did you compile this yourself?
Assigning this to @KrishnaIyer to look into this. This may take a while as he won't be back from holidays before mid next week.
BTW, what exactly is the format of your Authorization
header?
It should be: Authorization: Bearer <API Key>
@johanstokking, yeah that's what I'm doing. Also If I deliberately mangle the token to make it an invalid apikey I get different logs on the backend, the notable one being:
INFO Finished unary call duration=32.621167ms error=error:pkg/identityserver:invalid_authorization (invalid authorization) error_correlation_id=ee375627239e4b3c831b7e6adc02330b error_name=invalid_authorization error_namespace=pkg/identityserver grpc_code=Unauthenticated grpc_method=Get grpc_service=ttn.lorawan.v3.GatewayRegistry namespace=grpc request_id=01DM061EJM87C4GK7JNZW81QMX
So I think the token is being parsed correctly. What seems to be happening is there's an error whenever the first internal RPC call is made within the UpdateInfo
function in update_info.go
. Setting all the attributes as described above actually lets the call get all the way to the gateway Update
call near the end. Changing the attributes so that a different RPC call takes place (for example CreateAPIKey
by un-setting lns-credentials
) causes the 403 to be generated at that point instead.
That's as far as I've traced it so far.
So I've done a bit of research and I think I know what's kind of going on. It seems that the authentication passed in the update-info
is never used for any of the internal RPC call. If RegisterUnknown
is set then the configured APIKey will be used. If it's not things fall back to the default cluster auth?? I have no idea if this is really correct but the logical thing looking at the code is that the auth from the header should be used.
I've created a PR (#1344) which demonstrates a bit of a hacky solution. Feel free to discard if not useful, but I'm happy to spruce it up to standard if desired
Not that it's necessarily related, but I should point out this still doesn't solve all my issues in getting basicstation
working. update-info
now returns 200
, but on the basicstation
side I now get the error:
[AIO:ERRO] [3] Received more data than expected HTTP content size: 2187 extra bytes
If I find it's an unrelated issue I'll open another ticket, but I thought I'd just mention it.
Following up from a slack conversation with @adriansmares there seems to be a bit of uncertainty as to how and why auth works the way it does in this case.
There seems to be some agreement that the call that's failing originates from the Update
rpc call: https://github.com/TheThingsNetwork/lorawan-stack/blob/9262f5df0927ab437a10ca64fdcee008690444fd/pkg/basicstation/cups/update_info.go#L340
My query was then based around this call: https://github.com/TheThingsNetwork/lorawan-stack/blob/9262f5df0927ab437a10ca64fdcee008690444fd/pkg/basicstation/cups/update_info.go#L182
Following through the logic of this I've deduced the following. The call to getAuth
can do the following. If RegisterUnknown
has an apikey set in config this will be used to generate authorization
as referenced above. If RegisterUnknown
is not set the method will use s.component.WithClusterAuth()
. In no case does the value from the auth header get used in the getAuth
method despite it being passed. This just seems odd to me.
The impression from @adriansmares is that functionally speaking this behaviour may be correct, but to me this does seem odd. For one the getAuth
method has a signature that takes a parameter that's never used. Secondly if the s.component.WithClusterAuth()
allows for elevated privilege calls then that would seem to allow an apikey with the permissions to get a gateway to create a new apikey with higher privileges.
@htdvisser, do you have any insight into what the desired behaviour is here?
Let's try to have all discussions around this issue here on Github (and not on Slack) so that everyone has access to the full picture.
I set up a local test environment with the latest https://github.com/lorabasics/basicstation code and tried to reproduce the errors (which I could).
It looks like we need to make a bunch of changes to the way CUPS works. I'll take this issue over from @KrishnaIyer.
This is actually broken, so this is a bug for the current milestone.
Summary
Submitted as a result of a slack conversation. I've been trying to configure A Kerlink Wirnet Station using
basicstation
to connect to a v3 stack. When the station tries to callupdate-info
it errors with 403.Steps to Reproduce
RIGHT_GATEWAY_ALL
gateway_server_address
, and the attributescups-credentials
,lns-credentials
andcups-uri
. Not setting these either leads to a different cause of the 403 on the backend or a 500 error.basicstation
on the gateway setting the authorization header incups-boot.key
, the stack uri incups-boot.uri
and the stack cert incups-boot.trust
basicstation
What do you see now?
The backend logs for the request (these repeat as the gateway retries):
What do you want to see instead?
update-info
method should in these circumstances return OKEnvironment
v3.1.1 of the stack.
basicstation
is running on a Kerlink Wirnet Station. I can provide more info if relevant.Can you do this yourself and submit a Pull Request?
Maybe, but I would need help to work out what actually is going on first.