We present a generalization of the constrained density-functional theory approach to metallic and finite-temperature electronic systems, both in the canonical and grand-canonical ensembles. We find that the free-energy attains a unique maximum with respect to Lagrange multipliers whenever the applied constraints are satisfied, in each case. Analytical expressions are provided for the free-energy curvatures with respect to the Lagrange multipliers, as required for their automated non-linear optimization. Our extension is general to arbitrary constraints on the spin-polarized density, or on the density-matrix in the case of orbital-dependent constrained density-functional theory constrained non-locally. Our conclusion that the ground-state free-energy is concave with respect to Lagrange multipliers for finite-temperature systems is corroborated by numerical tests on a disparate pair of systems, namely a metallic hydrogen chain and a ferromagnetic metal oxide