You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

111 lines
4.0 KiB

  1. # Copyright 2015, 2016 OpenMarket Ltd
  2. # Copyright 2020 The Matrix.org Foundation C.I.C.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from ._base import Config
  16. class AuthConfig(Config):
  17. """Password and login configuration"""
  18. section = "auth"
  19. def read_config(self, config, **kwargs):
  20. password_config = config.get("password_config", {})
  21. if password_config is None:
  22. password_config = {}
  23. self.password_enabled = password_config.get("enabled", True)
  24. self.password_localdb_enabled = password_config.get("localdb_enabled", True)
  25. self.password_pepper = password_config.get("pepper", "")
  26. # Password policy
  27. self.password_policy = password_config.get("policy") or {}
  28. self.password_policy_enabled = self.password_policy.get("enabled", False)
  29. # User-interactive authentication
  30. ui_auth = config.get("ui_auth") or {}
  31. self.ui_auth_session_timeout = self.parse_duration(
  32. ui_auth.get("session_timeout", 0)
  33. )
  34. def generate_config_section(self, config_dir_path, server_name, **kwargs):
  35. return """\
  36. password_config:
  37. # Uncomment to disable password login
  38. #
  39. #enabled: false
  40. # Uncomment to disable authentication against the local password
  41. # database. This is ignored if `enabled` is false, and is only useful
  42. # if you have other password_providers.
  43. #
  44. #localdb_enabled: false
  45. # Uncomment and change to a secret random string for extra security.
  46. # DO NOT CHANGE THIS AFTER INITIAL SETUP!
  47. #
  48. #pepper: "EVEN_MORE_SECRET"
  49. # Define and enforce a password policy. Each parameter is optional.
  50. # This is an implementation of MSC2000.
  51. #
  52. policy:
  53. # Whether to enforce the password policy.
  54. # Defaults to 'false'.
  55. #
  56. #enabled: true
  57. # Minimum accepted length for a password.
  58. # Defaults to 0.
  59. #
  60. #minimum_length: 15
  61. # Whether a password must contain at least one digit.
  62. # Defaults to 'false'.
  63. #
  64. #require_digit: true
  65. # Whether a password must contain at least one symbol.
  66. # A symbol is any character that's not a number or a letter.
  67. # Defaults to 'false'.
  68. #
  69. #require_symbol: true
  70. # Whether a password must contain at least one lowercase letter.
  71. # Defaults to 'false'.
  72. #
  73. #require_lowercase: true
  74. # Whether a password must contain at least one lowercase letter.
  75. # Defaults to 'false'.
  76. #
  77. #require_uppercase: true
  78. ui_auth:
  79. # The amount of time to allow a user-interactive authentication session
  80. # to be active.
  81. #
  82. # This defaults to 0, meaning the user is queried for their credentials
  83. # before every action, but this can be overridden to allow a single
  84. # validation to be re-used. This weakens the protections afforded by
  85. # the user-interactive authentication process, by allowing for multiple
  86. # (and potentially different) operations to use the same validation session.
  87. #
  88. # Uncomment below to allow for credential validation to last for 15
  89. # seconds.
  90. #
  91. #session_timeout: "15s"
  92. """