In many treatments of statistical mechanics, I have seen a derivation of the canonical and grand canonical distributions by maximizing the entropy in equilibrium with appropriate constraints using Lagrange multipliers. However, I know for a fact that the entropy of a non-isolated system can decrease, provided that the total entropy of the system plus its surroundings increases.
Why then can we get these distributions which talk about non-isolated systems with maximizing the system's entropy, without also thinking about the environment? Shouldn't we be using other appropriate thermodynamic potentials for this?