"... Ownership of objects launched into outer space, including objects landed or constructed on a celestial body, and of their component parts, is not affected by their presence in outer space or on a celestial body or by their return to the Earth..." . (Outer Space Treaty)
This has been interpreted as meaning that if you construct a habitat on the Moon or use materials from an asteroid to construct a habitat in space, that you own the habitat though not the Moon or asteroid.