Skip to content

Commit aa5d8c8

Browse files
committed
Revert "19473: Azure App Registrations: Add maximum credential v..."
Revert submission 134124-azure Reason for revert: Need to change werk text and default params. Better revert and reland sot that also backporting will be easier Reverted changes: /q/submissionid:134124-azure Change-Id: Ia4c64acdad0ea17707d151ca0018a9930fd6420a
1 parent d0597c6 commit aa5d8c8

6 files changed

Lines changed: 51 additions & 273 deletions

File tree

.werks/19473.md

Lines changed: 0 additions & 26 deletions
This file was deleted.

packages/cmk-plugins/cmk/plugins/azure_v2/agent_based/azure_app_registration.py

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
CheckPlugin,
1717
CheckResult,
1818
DiscoveryResult,
19-
LevelsT,
19+
FixedLevelsT,
2020
render,
2121
Result,
2222
Service,
@@ -27,36 +27,22 @@
2727

2828
THIRTY_DAYS = 30 * 24 * 60 * 60.0
2929
SEVEN_DAYS = 7 * 24 * 60 * 60.0
30-
ONE_YEAR = 365 * 24 * 60 * 60.0
31-
TWO_YEARS = 2 * ONE_YEAR
3230

3331

34-
class _CredentialParams(TypedDict, total=False):
35-
remaining_validity: LevelsT[float]
36-
max_validity: LevelsT[float]
37-
38-
39-
class Params(TypedDict, total=False):
40-
secrets: _CredentialParams
41-
certificates: _CredentialParams
32+
class Params(TypedDict):
33+
expiration_time_secrets: FixedLevelsT[float]
34+
expiration_time_certificates: FixedLevelsT[float]
4235

4336

4437
DEFAULT_PARAMS = Params(
45-
secrets=_CredentialParams(
46-
remaining_validity=("fixed", (THIRTY_DAYS, SEVEN_DAYS)),
47-
max_validity=("fixed", (ONE_YEAR, TWO_YEARS)),
48-
),
49-
certificates=_CredentialParams(
50-
remaining_validity=("fixed", (THIRTY_DAYS, SEVEN_DAYS)),
51-
max_validity=("fixed", (ONE_YEAR, TWO_YEARS)),
52-
),
38+
expiration_time_secrets=("fixed", (THIRTY_DAYS, SEVEN_DAYS)),
39+
expiration_time_certificates=("fixed", (THIRTY_DAYS, SEVEN_DAYS)),
5340
)
5441

5542

5643
class Credential(BaseModel):
5744
appId: str
5845
appName: str
59-
startDateTime: str | None = None
6046
endDateTime: str
6147
keyId: str
6248
customKeyIdentifier: str | None = None
@@ -124,8 +110,7 @@ def discover_certificates(section: Section) -> DiscoveryResult:
124110

125111
def _check_credential_expiration(
126112
credential: Credential,
127-
remaining_validity: LevelsT[float] | None,
128-
max_validity: LevelsT[float] | None,
113+
params: FixedLevelsT[float],
129114
credential_type: Literal["Secret", "Certificate"],
130115
) -> CheckResult:
131116
expiration_date = parse_azure_datetime(credential.endDateTime)
@@ -136,51 +121,31 @@ def _check_credential_expiration(
136121
state=State.CRIT,
137122
summary=f"{credential_type} expired: {render.timespan(abs(age))} ago",
138123
)
139-
elif remaining_validity is not None:
124+
else:
140125
yield from check_levels(
141126
age,
142-
levels_lower=remaining_validity,
127+
levels_lower=params,
143128
label="Remaining time",
144129
render_func=render.timespan,
145130
)
146-
else:
147-
yield Result(state=State.OK, summary=f"Remaining time: {render.timespan(age)}")
148-
149-
if (
150-
max_validity is not None
151-
and credential.startDateTime is not None # None with old agents output
152-
and max_validity[0] != "no_levels"
153-
):
154-
start_date = parse_azure_datetime(credential.startDateTime)
155-
total_validity = expiration_date.timestamp() - start_date.timestamp()
156-
yield from check_levels(
157-
total_validity,
158-
levels_upper=max_validity,
159-
label="Max validity",
160-
render_func=render.timespan,
161-
)
162131

163132

164133
def check_app_registration_secret(item: str, params: Params, section: Section) -> CheckResult:
165134
if (credential := section.secrets.get(item)) is None:
166135
return
167-
cred_params = params.get("secrets", {})
168136
yield from _check_credential_expiration(
169137
credential,
170-
remaining_validity=cred_params.get("remaining_validity"),
171-
max_validity=cred_params.get("max_validity"),
138+
params["expiration_time_secrets"],
172139
credential_type="Secret",
173140
)
174141

175142

176143
def check_app_registration_certificate(item: str, params: Params, section: Section) -> CheckResult:
177144
if (credential := section.certificates.get(item)) is None:
178145
return
179-
cred_params = params.get("certificates", {})
180146
yield from _check_credential_expiration(
181147
credential,
182-
remaining_validity=cred_params.get("remaining_validity"),
183-
max_validity=cred_params.get("max_validity"),
148+
params["expiration_time_certificates"],
184149
credential_type="Certificate",
185150
)
186151

packages/cmk-plugins/cmk/plugins/azure_v2/checkman/azure_v2_app_registration

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,13 @@ agents: azure_v2
33
catalog: cloud/azure
44
license: GPLv2
55
distribution: check_mk
6-
description: This check monitors validity of a Microsoft Azure
6+
description: This check monitors validity of an Microsoft Azure
77
app registration secret.
8-
The state of the service is CRIT if the secret has expired.
8+
The state of the service is CRIT if the secret has
9+
expired.
910

10-
Two threshold groups can be configured in the rule
11-
"Microsoft Azure App Registrations":
12-
13-
Remaining validity: Alert when the secret is about to expire.
14-
The default levels are WARN at 30 days and CRIT at 7 days.
15-
16-
Maximum allowed validity: Alert when the total lifespan of the secret
17-
(from creation to expiry) exceeds a threshold.
18-
The default levels are WARN at 1 year and CRIT at 2 years.
11+
The levels for remaining time until expiry can be
12+
configured in the rule "Azure App Registration".
1913

2014
In order to use this check, you need to configure the Azure special agent.
2115

packages/cmk-plugins/cmk/plugins/azure_v2/checkman/azure_v2_app_registration_certificates

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
title: Microsoft Azure App Registration Certificate
1+
title: Microsoft Azure App Registration Certficate
22
agents: azure_v2
33
catalog: cloud/azure
44
license: GPLv2
55
distribution: check_mk
6-
description: This check monitors validity of a Microsoft Azure
6+
description: This check monitors validity of an Microsoft Azure
77
app registration certificate.
8-
The state of the service is CRIT if the certificate has expired.
8+
The state of the service is CRIT if the certificate has
9+
expired.
910

10-
Two threshold groups can be configured in the rule
11-
"Microsoft Azure App Registrations":
12-
13-
Remaining validity: Alert when the certificate is about to expire.
14-
The default levels are WARN at 30 days and CRIT at 7 days.
15-
16-
Maximum allowed validity: Alert when the total lifespan of the certificate
17-
(from creation to expiry) exceeds a threshold. The default levels
18-
are WARN at 1 year and CRIT at 2 years.
11+
The levels for remaining time until expiry can be
12+
configured in the rule "Azure App Registration".
1913

2014
In order to use this check, you need to configure the Azure special agent.
2115

packages/cmk-plugins/cmk/plugins/azure_v2/rulesets/azure_app_registration.py

Lines changed: 26 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
44
# conditions defined in the file COPYING, which is part of this source code package.
55

6-
from collections.abc import Mapping
7-
86
from cmk.rulesets.v1 import Title
97
from cmk.rulesets.v1.form_specs import (
108
DefaultValue,
@@ -19,78 +17,42 @@
1917

2018
THIRTY_DAYS = 30 * 24 * 60 * 60.0
2119
SEVEN_DAYS = 7 * 24 * 60 * 60.0
22-
ONE_YEAR = 365 * 24 * 60 * 60.0
23-
TWO_YEARS = 2 * ONE_YEAR
24-
2520

26-
def _time_span() -> TimeSpan:
27-
return TimeSpan(
28-
displayed_magnitudes=[
29-
TimeMagnitude.DAY,
30-
TimeMagnitude.HOUR,
31-
TimeMagnitude.MINUTE,
32-
TimeMagnitude.SECOND,
33-
]
34-
)
3521

36-
37-
def _credential_validity_form(is_secret: bool) -> Dictionary:
22+
def _make_form() -> Dictionary:
3823
return Dictionary(
39-
title=Title("Check secret credentials")
40-
if is_secret
41-
else Title("Check certificate credentials"),
4224
elements={
43-
"remaining_validity": DictElement(
25+
"expiration_time_secrets": DictElement(
4426
parameter_form=SimpleLevels(
45-
title=Title("Remaining validity time"),
46-
form_spec_template=_time_span(),
27+
title=Title("Time until secret credentials expiration"),
28+
form_spec_template=TimeSpan(
29+
displayed_magnitudes=[
30+
TimeMagnitude.DAY,
31+
TimeMagnitude.HOUR,
32+
TimeMagnitude.MINUTE,
33+
TimeMagnitude.SECOND,
34+
]
35+
),
4736
level_direction=LevelDirection.LOWER,
4837
prefill_fixed_levels=DefaultValue((THIRTY_DAYS, SEVEN_DAYS)),
49-
),
38+
)
5039
),
51-
"max_validity": DictElement(
40+
"expiration_time_certificates": DictElement(
5241
parameter_form=SimpleLevels(
53-
title=Title("Maximum allowed validity"),
54-
form_spec_template=_time_span(),
55-
level_direction=LevelDirection.UPPER,
56-
prefill_fixed_levels=DefaultValue((ONE_YEAR, TWO_YEARS)),
57-
),
58-
),
59-
},
60-
)
61-
62-
63-
def _migrate(value: object) -> Mapping[str, object]:
64-
if not isinstance(value, dict):
65-
raise ValueError(value)
66-
67-
# Already in new nested format
68-
if "secrets" in value or "certificates" in value:
69-
return value
70-
71-
# Migrate from old flat format: expiration_time_secrets / expiration_time_certificates
72-
result: dict[str, object] = {}
73-
if "expiration_time_secrets" in value:
74-
result["secrets"] = {"remaining_validity": value["expiration_time_secrets"]}
75-
if "expiration_time_certificates" in value:
76-
result["certificates"] = {"remaining_validity": value["expiration_time_certificates"]}
77-
78-
return result
79-
80-
81-
def _make_form() -> Dictionary:
82-
return Dictionary(
83-
migrate=_migrate,
84-
elements={
85-
"secrets": DictElement(
86-
required=False,
87-
parameter_form=_credential_validity_form(is_secret=True),
88-
),
89-
"certificates": DictElement(
90-
required=False,
91-
parameter_form=_credential_validity_form(is_secret=False),
42+
title=Title("Time until certificate credentials expiration"),
43+
form_spec_template=TimeSpan(
44+
displayed_magnitudes=[
45+
TimeMagnitude.DAY,
46+
TimeMagnitude.HOUR,
47+
TimeMagnitude.MINUTE,
48+
TimeMagnitude.SECOND,
49+
]
50+
),
51+
level_direction=LevelDirection.LOWER,
52+
prefill_fixed_levels=DefaultValue((THIRTY_DAYS, SEVEN_DAYS)),
53+
)
9254
),
93-
},
55+
}
9456
)
9557

9658

0 commit comments

Comments
 (0)