Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blow up startup if init auth providers or modules failed #16240

Merged
merged 2 commits into from
Aug 28, 2018

Conversation

awarecan
Copy link
Contributor

Description:

Blow up startup if init auth providers or modules failed, either import module error or config error

Related issue (if applicable): fixes #

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.github.io#<home-assistant.github.io PR number goes here>

Example entry for configuration.yaml (if applicable):

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.

@awarecan awarecan requested a review from a team as a code owner August 28, 2018 09:47
@ghost ghost assigned awarecan Aug 28, 2018
@ghost ghost added in progress and removed core labels Aug 28, 2018
})
assert provider is None
with pytest.raises(vol.Invalid):
provider = await auth_provider_from_config(hass, None, {

Choose a reason for hiding this comment

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

local variable 'provider' is assigned to but never used

@pvizeli
Copy link
Member

pvizeli commented Aug 28, 2018

I don't think we should do that. Because in unattended system it is ugly

@awarecan
Copy link
Contributor Author

Failed load auth provider will leave system unprotected. Have discussion regarding this in #beta channel

@balloob
Copy link
Member

balloob commented Aug 28, 2018

An alternative is that when the config is invalid, we default to the default config and issue a warning? That way the system is still accessible?

@balloob
Copy link
Member

balloob commented Aug 28, 2018

Actually, we should not load a single config entry when auth is invalid, start in a "light" mode would be the best

@balloob
Copy link
Member

balloob commented Aug 28, 2018

Was talking with Pascal: if config validation passes, HASS should successfully startup. If not, it's ok to fail.

@awarecan
Copy link
Contributor Author

Double confirm my understanding is right, in bootstrap.async_from_config_dict

try:
    await async_process_ha_core_config();
except vol.Invalid:
    return None                # startup will hang
except HomeAssistantError:     # such as import error
    _LOGGER.error()
    return None                # (Solution A) startup will hang
or
    return hass                # (Solution B) a minimal HASS
or
    pass                       # (Solution C) a HASS without auth protection

So which solution is our final decision?

@@ -901,3 +901,20 @@ def test_merge_customize(hass):
}
with pytest.raises(Invalid):
await config_util.async_process_ha_core_config(hass, core_config)


async def test_disallowed_auth_provider_config(hass):

Choose a reason for hiding this comment

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

redefinition of unused 'test_disallowed_auth_provider_config' from line 889


from homeassistant import auth, data_entry_flow
from homeassistant.auth import (
models as auth_models, auth_store, const as auth_const)
from homeassistant.auth.mfa_modules import SESSION_EXPIRATION
from homeassistant.exceptions import HomeAssistantError

Choose a reason for hiding this comment

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

'homeassistant.exceptions.HomeAssistantError' imported but unused

@awarecan awarecan changed the title Blow up startup if init auth providers or modules failed WIP: Blow up startup if init auth providers or modules failed Aug 28, 2018
@awarecan awarecan changed the title WIP: Blow up startup if init auth providers or modules failed Blow up startup if init auth providers or modules failed Aug 28, 2018
@awarecan
Copy link
Contributor Author

Have moved duplicate auth provider check to schema, so all config issue will raise vol.Invalid.

I implemented as Solution A right now, startup will hang if load auth provider/mfa module failed. But can easily change to Solution B or C.

Copy link
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

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

I think this is perfect.

I wonder if we also need to validate CONF_TYPE exists, but that might be for another PR.

@balloob balloob merged commit 257b8b9 into home-assistant:dev Aug 28, 2018
@ghost ghost removed the in progress label Aug 28, 2018
@balloob balloob added this to the 0.77 milestone Aug 28, 2018
@awarecan awarecan deleted the fail-startup branch August 28, 2018 18:56
balloob pushed a commit that referenced this pull request Aug 28, 2018
* Blow up startup if init auth providers or modules failed

* Delete core.entity_registry
@balloob balloob mentioned this pull request Aug 29, 2018
girlpunk pushed a commit to girlpunk/home-assistant that referenced this pull request Sep 4, 2018
…ant#16240)

* Blow up startup if init auth providers or modules failed

* Delete core.entity_registry
@home-assistant home-assistant locked and limited conversation to collaborators Dec 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants