Montana judge upholds ruling that canceled Keystone XL pipeline permit