Skip to content

Commit 7f725f0

Browse files
committed
MINOR: proxy: prevent deletion of backend referenced by config elements
Define a new proxy flag PR_FL_NON_PURGEABLE. This is used to mark every proxy instance explicitely referenced in the config. Such instances cannot be deleted at runtime. Static use_backend/default_backend rules are handled in proxy_finalize(). Also, sample expression proxy references are protected via smp_resolve_args(). Note that this last case also incidentally protects any proxies referenced via a CLI "set var" expression. This should not be the case as in this case variable value is instantly resolved so the proxy reference is not needed anymore. This also affects dynamic servers.
1 parent 7bf3020 commit 7f725f0

4 files changed

Lines changed: 25 additions & 6 deletions

File tree

doc/management.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,10 +2130,12 @@ del backend <name>
21302130
This operation is only possible for TCP or HTTP proxies. To succeed, the
21312131
backend instance must have been first unpublished.
21322132

2133-
There is also additional restrictions which prevent backend removal.
2134-
Currently, this is the case when deprecated dispatch or option transparent
2135-
are used. Also, a backend cannot be removed if there is a stick-table
2136-
declared in it.
2133+
There is additional restrictions which prevent backend removal. First, a
2134+
backend cannot be removed if it is explicitely referenced by config elements,
2135+
for example via a use_backend rule or in sample expressions. Some proxies
2136+
options are also incompatible with runtime deletion. Currently, this is the
2137+
case when deprecated dispatch or option transparent are used. Also, a backend
2138+
cannot be removed if there is a stick-table declared in it.
21372139

21382140
This command is restricted and can only be issued on sockets configured for
21392141
level "admin". Moreover, this feature is still considered in development so it

include/haproxy/proxy-t.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ enum PR_SRV_STATE_FILE {
248248
#define PR_FL_CHECKED 0x00000040 /* The proxy configuration was fully checked (including postparsing checks) */
249249
#define PR_FL_BE_UNPUBLISHED 0x00000080 /* The proxy cannot be targetted by content switching rules */
250250
#define PR_FL_DELETED 0x00000100 /* Proxy has been deleted and must be manipulated with care */
251+
#define PR_FL_NON_PURGEABLE 0x00000200 /* Proxy referenced by config elements which prevent its runtime removal. */
251252

252253
struct stream;
253254

src/proxy.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,6 +1982,8 @@ int proxy_finalize(struct proxy *px, int *err_code)
19821982
*/
19831983
px->options |= PR_O_HTTP_UPG;
19841984
}
1985+
1986+
target->flags |= PR_FL_NON_PURGEABLE;
19851987
}
19861988
}
19871989

@@ -2058,6 +2060,8 @@ int proxy_finalize(struct proxy *px, int *err_code)
20582060
*/
20592061
px->options |= PR_O_HTTP_UPG;
20602062
}
2063+
2064+
target->flags |= PR_FL_NON_PURGEABLE;
20612065
}
20622066
*err_code |= warnif_tcp_http_cond(px, rule->cond);
20632067
}
@@ -5014,6 +5018,11 @@ int be_check_for_deletion(const char *bename, struct proxy **pb, const char **pm
50145018
goto out;
50155019
}
50165020

5021+
if (be->cap & PR_CAP_FE) {
5022+
msg = "Cannot delete a listen section.";
5023+
goto out;
5024+
}
5025+
50175026
if (be->options & (PR_O_DISPATCH|PR_O_TRANSP)) {
50185027
msg = "Deletion of backend with deprecated dispatch/transparent options is not supported.";
50195028
goto out;
@@ -5024,8 +5033,8 @@ int be_check_for_deletion(const char *bename, struct proxy **pb, const char **pm
50245033
goto out;
50255034
}
50265035

5027-
if (be->cap & PR_CAP_FE) {
5028-
msg = "Cannot delete a listen section.";
5036+
if (be->flags & PR_FL_NON_PURGEABLE) {
5037+
msg = "This proxy cannot be removed at runtime due to other configuration elements pointing to it.";
50295038
goto out;
50305039
}
50315040

src/sample.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,7 @@ int smp_resolve_args(struct proxy *p, char **err)
15121512
break;
15131513
}
15141514

1515+
/* TODO CLI set-var should not prevent server deletion as var value is instantly resolved. */
15151516
srv->flags |= SRV_F_NON_PURGEABLE;
15161517

15171518
chunk_destroy(&arg->data.str);
@@ -1541,6 +1542,9 @@ int smp_resolve_args(struct proxy *p, char **err)
15411542
break;
15421543
}
15431544

1545+
/* TODO CLI set-var should not prevent proxy deletion as var value is instantly resolved. */
1546+
px->flags |= PR_FL_NON_PURGEABLE;
1547+
15441548
chunk_destroy(&arg->data.str);
15451549
arg->unresolved = 0;
15461550
arg->data.prx = px;
@@ -1568,6 +1572,9 @@ int smp_resolve_args(struct proxy *p, char **err)
15681572
break;
15691573
}
15701574

1575+
/* TODO CLI set-var should not prevent proxy deletion as var value is instantly resolved. */
1576+
px->flags |= PR_FL_NON_PURGEABLE;
1577+
15711578
chunk_destroy(&arg->data.str);
15721579
arg->unresolved = 0;
15731580
arg->data.prx = px;

0 commit comments

Comments
 (0)