Replace api_password in Camera.Push#16339
Conversation
awarecan
left a comment
There was a problem hiding this comment.
Should add note in PR description regarding breaking changes
| vol.Optional(CONF_TIMEOUT, default=timedelta(seconds=5)): vol.All( | ||
| cv.time_period, cv.positive_timedelta), | ||
| vol.Optional(CONF_IMAGE_FIELD, default='image'): cv.string, | ||
| vol.Required(CONF_TOKEN): vol.All(cv.string, vol.Length(min=8)), |
There was a problem hiding this comment.
Since you accept bearer token, CONF_TOKEN should be optional.
awarecan
left a comment
There was a problem hiding this comment.
Cannot find test case to test return HTTP status 401, i.e. wrong token or missed token scenario
tests/components/camera/test_push.py
Outdated
| assert resp.status == 400 | ||
| assert resp.status == 404 | ||
|
|
||
| # wrong token but authenticated user |
There was a problem hiding this comment.
Did I missed something? How this be authenticated user? I didn't find the code to set Authorization header.
There was a problem hiding this comment.
client always makes authenticated requests... how can I disable it ?
There was a problem hiding this comment.
|
tests added 👍 |
|
Maybe we should wait until the long time tokens are implemented and we can switch to this common version. Otherwise it going to a edge case for handling auth. |
|
I'm all in favor of using long time tokens. But I was under the impression from #15376 (comment) that long time tokens would not become an option and that the current api_password would be dropped soon. |
| vol.Optional(CONF_TIMEOUT, default=timedelta(seconds=5)): vol.All( | ||
| cv.time_period, cv.positive_timedelta), | ||
| vol.Optional(CONF_IMAGE_FIELD, default='image'): cv.string, | ||
| vol.Optional(CONF_TOKEN): vol.All(cv.string, vol.Length(min=8)), |
There was a problem hiding this comment.
I made it optional, since the implementation allows the use of the normal authentication.
|
@pvizeli we don't want to use long lived access tokens for this because an access token would allow full access. For these one off access, just allowing an auth token to be hard coded is fine. |
|
This is ok to merge once the token has been changed in the schema to be required. |
|
I see this PR as a stop-gap, what we need are long lived access tokens that are limited to given API's The preferred authentication and authorisation method should be that of HA, and that is why I keep the option of uploading the camera images using HA auth. |
| config[CONF_BUFFER_SIZE], | ||
| config[CONF_TIMEOUT])] | ||
| config[CONF_TIMEOUT], | ||
| config[CONF_TOKEN])] |
There was a problem hiding this comment.
This expects the CONF_TOKEN to be always set, which is not the case as it can be optional.
| status) | ||
|
|
||
| authenticated = (request[KEY_AUTHENTICATED] or | ||
| request.query.get('token') == _camera.token) |
There was a problem hiding this comment.
Not setting a token will result in token being None, so then not passing a token means we're checking None == None, allowing user to always access it.
|
Putting this in the 0.78 release as example how to do auth both ways. As far as I can see, this is not a breaking change as people can still authenticate with API password via legacy API password provider, or even use new auth. |
|
It you don't remove legacy_api that is true :) I was afraid that it was going out in 0.78 already... |
|
Oh no, that beast will probably be around for a looooooooong time. Eventually it will become opt-in instead of opt-out. |
|
But first we need long lived access tokens, which will come this release. |
* Use access_token and user provided token instead of api_password * address comments by @awarecan * new tests * add extra checks and test * lint * add comment
Description:
Remove api_password, and changes to using access_token/user provided token accordingly to #15376 (comment)
This is a breaking change for most users pushing camera images through cURL scripts
Related issue (if applicable): #15376
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#6130
Example entry for
configuration.yaml(if applicable):Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
REQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.If the code does not interact with devices: