||Fog computing is a promising Internet of Things (IoT) paradigm in which data is processed near its source. Here, efficient resource allocation mechanisms are needed to assign limited fog resources to competing IoT tasks. To this end, we consider two challenges: (1) nearoptimal resource allocation in a fog computing system; (2) incentivising self-interested fog users to report their tasks truthfully. To address these challenges, we develop a truthful online resource allocation mechanism called flexible online greedy. The key idea is that the mechanism only commits a certain amount of computational resources to a task when it arrives. However, when and where to allocate resources stays flexible until the completion of the task. We compare our mechanism to four benchmarks and show that it outperforms all of them in terms of social welfare by up to 10% and achieves a social welfare of about 90% of the offline optimal upper bound.