Gauge invariance for generally covariant systems