Skip to content

Replace api_password in Camera.Push#16339

Merged
balloob merged 6 commits intohome-assistant:devfrom
dgomes:camera.push-token
Sep 11, 2018
Merged

Replace api_password in Camera.Push#16339
balloob merged 6 commits intohome-assistant:devfrom
dgomes:camera.push-token

Conversation

@dgomes
Copy link
Copy Markdown
Contributor

@dgomes dgomes commented Aug 31, 2018

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):

camera:
  - platform: push
    name: cam1
    timeout: 10
    cache: 5
    token: 12345678

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New or updated dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

@ghost ghost assigned dgomes Aug 31, 2018
@ghost ghost added the in progress label Aug 31, 2018
@dgomes dgomes changed the title Use access_token and user provided token instead of api_password Replace api_password Aug 31, 2018
@dgomes dgomes changed the title Replace api_password Replace api_password in Camera.Push Aug 31, 2018
Copy link
Copy Markdown
Contributor

@awarecan awarecan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you accept bearer token, CONF_TOKEN should be optional.

Copy link
Copy Markdown
Contributor

@awarecan awarecan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot find test case to test return HTTP status 401, i.e. wrong token or missed token scenario

assert resp.status == 400
assert resp.status == 404

# wrong token but authenticated user
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did I missed something? How this be authenticated user? I didn't find the code to set Authorization header.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

client always makes authenticated requests... how can I disable it ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dgomes dgomes removed the in progress label Sep 1, 2018
@ghost ghost added the in progress label Sep 1, 2018
@dgomes
Copy link
Copy Markdown
Contributor Author

dgomes commented Sep 1, 2018

tests added 👍

@pvizeli
Copy link
Copy Markdown
Member

pvizeli commented Sep 3, 2018

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.

@dgomes
Copy link
Copy Markdown
Contributor Author

dgomes commented Sep 3, 2018

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)),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be required

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it optional, since the implementation allows the use of the normal authentication.

@balloob
Copy link
Copy Markdown
Member

balloob commented Sep 4, 2018

@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.

@balloob
Copy link
Copy Markdown
Member

balloob commented Sep 4, 2018

This is ok to merge once the token has been changed in the schema to be required.

@dgomes
Copy link
Copy Markdown
Contributor Author

dgomes commented Sep 4, 2018

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])]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@oblogic7 oblogic7 mentioned this pull request Sep 9, 2018
8 tasks
@dgomes dgomes closed this Sep 10, 2018
@dgomes dgomes reopened this Sep 10, 2018
@ghost ghost added the in progress label Sep 10, 2018
@balloob balloob added this to the 0.78.0 milestone Sep 11, 2018
@balloob balloob merged commit 20f6cb7 into home-assistant:dev Sep 11, 2018
@ghost ghost removed the in progress label Sep 11, 2018
@balloob
Copy link
Copy Markdown
Member

balloob commented Sep 11, 2018

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.

@dgomes
Copy link
Copy Markdown
Contributor Author

dgomes commented Sep 11, 2018

It you don't remove legacy_api that is true :)

I was afraid that it was going out in 0.78 already...

@balloob
Copy link
Copy Markdown
Member

balloob commented Sep 11, 2018

Oh no, that beast will probably be around for a looooooooong time. Eventually it will become opt-in instead of opt-out.

@balloob
Copy link
Copy Markdown
Member

balloob commented Sep 11, 2018

But first we need long lived access tokens, which will come this release.

balloob pushed a commit that referenced this pull request Sep 11, 2018
* 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
@balloob balloob mentioned this pull request Sep 17, 2018
@dgomes dgomes deleted the camera.push-token branch November 11, 2018 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants